GithubHelp home page GithubHelp logo

js-devtools / globify Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 6.0 1.24 MB

Run browserify and watchify with globs - even on Windows!

Home Page: https://jstools.dev/globify/

License: MIT License

JavaScript 100.00%
nodejs browserify cli cross-platform windows macos linux globs glob-pattern

globify's Introduction

Globify

Run browserify and watchify with globs - even on Windows!

Cross-Platform Compatibility Build Status

Coverage Status Dependencies

npm License Buy us a tree

Features

  • Supports glob patterns for entry files - even on Windows
  • Optionally create separate browserify bundles for each entry file

Related Projects

Installation

Install using npm. Add the -g flag to install globally so you can use it from any terminal.

npm install -g @jsdevtools/globify

Usage

The command-line interface is identical to browserify and watchify. In fact, globify simply passes your arguments straight to browserify or watchify (after expanding the glob pattern).

globify <entry files glob>  [options]

Options:

  <entry files glob>

    Glob pattern of entry files. Don't forget to wrap the glob pattern in quotes,
    otherwise some shells (like bash) will pre-expand the glob.

  --outfile=FILE, -o FILE

    If outfile is a file, then a single bundle will be created.  If it's a directory,
    then separate bundles will be created for each entry file.  You can also specify
    an output filename pattern, like *.bundled.js

  --exclude=GLOB, -u GLOB

    Excludes files that are matched by the <entry files glob>

  --watch, -w

    Call watchify instead of browserify.

Examples

For all of these examples, assume that we have a file structure like this:

lib/
 |__ my-entry-file.js
 |__ some-file.js
 |__ other-file.js
 |__ other-entry-file.js
 |__ subdir/
       |__ another-entry-file.js
       |__ another-file.js
       |__ yet-another-file.js

Multiple files in one bundle

We want to bundle all three entry files into a single bundle file. We can do that with the following command:

globify "lib/**/*-entry-file.js" --outfile=dist/my-bundle.js

Globify will call browserify once, passing it the three matching entry files and one bundle file:

browserify lib/my-entry-file.js lib/other-entry-file.js lib/subdir/another-entry-file.js --outfile=dist/my-bundle.js

Multiple files, multiple bundles

We want to create separate bundle files for each of the three entry files. We can do that with the following command:

globify "lib/**/*-entry-file.js" --outfile=dist

Globify will call browserify three times (once for each entry file), and create three corresponding bundles:

browserify lib/my-entry-file.js --outfile=dist/my-entry-file.js
browserify lib/other-entry-file.js --outfile=dist/other-entry-file.js
browserify lib/subdir/another-entry-file.js --outfile=dist/subdir/another-entry-file.js

Multiple files, multiple bundles with customized names

We want to create separate bundle files for each of the three entry files, but we weant each bundle file to have a .bundled.js suffix. We can do that with the following command:

globify "lib/**/*-entry-file.js" -o "dist/*.bundled.js"

Globify will call browserify three times (once for each entry file) and create three corresponding bundles:

browserify lib/my-entry-file.js -o dist/my-entry-file.bundled.js
browserify lib/other-entry-file.js -o dist/other-entry-file.bundled.js
browserify lib/subdir/another-entry-file.js -o dist/subdir/another-entry-file.bundled.js

Watchify, transforms, other options

Now, let's try it with watchify instead. Let's also add some extra options, and run the uglifyify transforms to minify the bundles. And let's give the bundles a .bundled.min.js suffix.

globify -g uglifyify "lib/**/*-entry-file.js" -w -v -d -o "dist/*.bundled.min.js"

Globify will call watchify (because of the -w option) three times with all of the specified options:

watchify -g uglifyify lib/my-entry-file.js -v -d -o dist/my-entry-file.bundled.min.js
watchify -g uglifyify lib/other-entry-file.js -v -d -o dist/other-entry-file.bundled.min.js
watchify -g uglifyify lib/subdir/another-entry-file.js -v -d -o dist/subdir/another-entry-file.bundled.min.js

Contributing

Contributions, enhancements, and bug-fixes are welcome! Open an issue on GitHub and submit a pull request.

Building/Testing

To build/test the project locally on your computer:

  1. Clone this repo
    git clone https://github.com/JS-DevTools/globify.git

  2. Install dependencies
    npm install

  3. Run the tests
    npm test

License

Globify is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

Travis CI SauceLabs Coveralls

globify's People

Contributors

greenkeeperio-bot avatar jamesmessinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

globify's Issues

Excellent useful and helpful project

No issue here, I just wanted to praise you for creating globify!

Been fighting using globs with npm scripts, browserify, and Windows. This project was the saving grace I've been trying to find for over 2 weeks.

While piping would be nice (so I can only use globify and not need to install watchify and browserify), I just wanted to thank you for the project and maintaining it!

Support watchify pipe output option

The watchify docs say:

--outfile=FILE, -o FILE

This option is required. Write the browserify bundle to this file. If
the file contains the operators `|` or `>`, it will be treated as a
shell command, and the output will be piped to it.

Problem is that if you provide the outputfile something like the examples given

-o 'exorcist static/bundle.js.map > static/bundle.js'

globify does not recognise it as such and creates a folder instead.

Uglifyjs support

From the Ugligyfyify docs:

"Uglifyify provides an additional optimization when used with Uglify, but does not provide all of the optimization that using Uglify on its own does, so it's not a replacement."

And indeed the bundle size resulting from uglifyify is bigger than the one produced by normal Uglifyjs2.
Is it possible to apply normal uglify with globify?

Related to #3

Exclude from glob

Is there a way to exclude certain patterns, like for example the node_modules directory?
Maybe something in the lines of what bash supports? **/*.coffee!(*node_modules*)

Watch subclasses build main classes

Couldn't think of better title...
Here is an example of project structure:

lib/
 |__ cars.js
 |__ animals.js
 |__ classes/
       |__ dog.js
       |__ cat.js
       |__ volvo.js
       |__ porshe.js

currently it is only possible to watch main files and compile corresponding files...
e.g. if globify 'lib/*.js' -w -v -o 'lib/out' it will compile only when cars.js or animals.js is changed
is there any way to watch for all js in lib and compile cars.js and animals.js
or at least watch for all and compile all files?

Options -v -d

These options appear in the a REAME example but doesn't seem to be any more information about them.

Using the programmatic API of browserify

Is there any reason you don't use the programmatic API of browserify/watchify

Spawning a new process for every entry point seems slow to me.

Would you accept a PR that would leverage the programmatic API of the tools?

Output to file next to input file

I'm trying to find all .coffee files in my directory tree and have globify output .js files next to them. Is this possible without having a single directory as a destination?

Parse arbritary glob parameters

The idea is to find all the * inside a string and replace the * with the file name like it is done for the --outfile paramenter.

This is what I'm trying to do:

 globify -t coffeeify 'coffee/*.coffee' --debug -p [minifyify --map 'js/*.map.json' --output 'js/*.map.json'] --outfile 'js/*.js'

But results in this:

browserify -t coffeeify coffee/content-gist.coffee --debug -p [minifyify --map js/*.map.json --output js/*.map.json] --outfile js/content-gist.js
browserify -t coffeeify coffee/content-import.coffee --debug -p [minifyify --map js/*.map.json --output js/*.map.json] --outfile js/content-import.js
browserify -t coffeeify coffee/eventPage.coffee --debug -p [minifyify --map js/*.map.json --output js/*.map.json] --outfile js/eventPage.js
browserify -t coffeeify coffee/options.coffee --debug -p [minifyify --map js/*.map.json --output js/*.map.json] --outfile js/options.js
browserify -t coffeeify coffee/test.coffee --debug -p [minifyify --map js/*.map.json --output js/*.map.json] --outfile js/test.js

If you have any other suggestions on how to achieve multiple file uglify with working coffeescript source maps please advise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.