Détail du package

powerbuild

tarruda660.0.11

CommonJS bundler with aliasing, extensibility, and source maps from the minified JS bundle. Forked from commonjs-everywhere adding speed improvements, persistent disk cache for incremental builds, support for reading '// [#@] sourceMappingURL' from input files and bundled grunt task

CommonJS, CommonJS Everywhere, browser, build

readme

Powerbuild

CommonJS bundler with aliasing, extensibility, and source maps from the minified JS bundle. Forked from commonjs-everywhere adding speed improvements, persistent disk cache for incremental builds, support for reading '// [#@] sourceMappingURL' from input files and bundled grunt task

Main changes from commonjs-everywhere

  • Escodegen is only used when generating partial source maps, the final result is computed manually.
  • For minification esmangle/escodegen is replaced by UglifyJS for two reasons:
    • It was breaking in some of my tests
    • It is 10x slower than UglifyJS. For a bundle with 50k lines of code UglifyJS took about 4 seconds versus 35 seconds from esmangle/escodegen)
  • Dependency on coffee-script-redux was removed. While its still possible to use the 'handlers' option to build compile-to-js languages directly, this tool now reads '// @sourceMappingURL' tags from the end of the file in order to map correctly to the original files. This means any compile-to-js language that produces source maps is supported out-of-box.
  • By default, source maps for npm dependencies are not included.
  • Module paths are replaced by unique identifiers, which leads to a small improvement in the resulting size. When the filename or dirname variables are used, a mapping for that module uid to the filename will be used.
  • Multiple entry points can be specified, with the last being exported if the 'export' option is used. This can be used to create test bundles.
  • The result is wrapped into UMD.
  • If the 'node' option is unset, it will disable node.js emulation and inclusion of core modules. The result can be loaded as a normal node.js module.

Install

npm install -g powerbuild

Usage

CLI

$ bin/powerbuild --help

  Usage: powerbuild OPT* ENTRY_FILE+ OPT*

  -a, --alias ALIAS:TO      replace requires of file identified by ALIAS with TO
  -h, --handler EXT:MODULE  handle files with extension EXT with module MODULE
  -m, --minify              minify output using uglify.js
  -c, --compress            Compress/optimize code when minifying
                            (automatically enabled by this option). Enabling
                            will break the generated source map.
  -o, --output FILE         output to FILE instead of stdout
  -r, --root DIR            unqualified requires are relative to DIR; default: cwd
  -s, --source-map FILE     output a source map to FILE
  -v, --verbose             verbose output sent to stderr
  -w, --watch               watch input files/dependencies for changes and rebuild bundle
  -x, --export NAME         export the last given entry module as NAME
  --deps                    do not bundle; just list the files that would be bundled
  --help                    display this help message and exit
  --ignore-missing          continue without error when dependency resolution fails
  --inline-source-map       include the source map as a data URI in the generated bundle
  --inline-sources          include source content in generated source maps
  --node                    if needed by any module, emulate a node.js 
                            environment by including globals such as Buffer,
                            process and setImmediate; default: on
  --cache-path              file where to read/write a json-encoded cache that
                            is used for fast, incremental builds.
                            default: '.powerbuild-cache~' in the current
                            directory
  --disable-disk-cache      disables persistence of incremental build cache
                            to disk. Incremental build will only work with the
                            --watch option
  --npm-source-maps         add mappings for npm modules in the resulting
                            source map(significantly increases the build time)
  --version                 display the version number and exit

Note: use - as an entry file to accept JavaScript over stdin

Note: to disable an option, prefix it with no-, e.g. --no-node

Example:

Common usage, a single entry point which will be used to build the entire dependency graph. Whatever is exported by 'entry-file.js' will go to the global property 'MyLibrary':

powerbuild src/entry-file.js --export MyLibrary --source-map my-library.js.map >my-library.js

Specify multiple entry points which will be "required" at startup. Only the last entry point will be exported when used in conjunction with the '--export' option. This is mostly useful for building test bundles which can be referenced from a single 'script' tag

powerbuild test/*.js --source-map tests.js.map -o tests.js

Watch every file in the dependency graph and rebuild when a file changes. Unlike commonjs-everywhere, this tool caches partial builds to disk, so this is not necessary for incremental builds.

powerbuild -wo my-library.js -x MyLibrary src/entry-file.js

Use a browser-specific version of /lib/node-compatible.js (remember to use root-relative paths for aliasing). An empty alias target is used to delay errors to runtime when requiring the source module (fs in this case). The 'browser' field in package.json will also be used if available when building bundles with node.js emulation(which is the default).

powerbuild -a /lib/node-compatible.js:/lib/browser-compatible.js -a fs: -x MyLibrary lib/entry-file.js

Module Interface

new Powerbuild(options)

Constructor for an object that can keeps track of build options and is used to trigger incremental rebuilds.

  • options is an object that can contain the following properties:
    • entryPoints is an array of filenames relative to process.cwd() that will be used to initialize the bundle. The last item in this array will also be used when the 'export' option is specified
    • root: Same as cli.
    • export: Same as cli.
    • aliases: an object whose keys and values are root-rooted paths (/src/file.js), representing values that will replace requires that resolve to the associated keys
    • handlers: an object whose keys are file extensions ('.coffee') and whose values are functions that receives the file contents as arguments and returns one of the following:
      • Spidermonkey-format JS AST like the one esprima produces
      • A string of javascript
      • An object with the keys 'code' and 'map' containing strings with javascript and sourcemaps respectively. A handler for JSON is included by default. If no handler is defined for a file extension, it is assumed to be JavaScript. (The default coffeescript-redux handler was removed because this tool now reads '// @sourceMappingURL' comment tags, so it can be used in conjunction with the default coffeescript compiler)
    • node: Same as cli. When true(default) the bundling phase will emit globals for 'process', 'Buffer' or 'setImmediate' if any of those are used by any of the bundled modules. Setting this to false will completely disable node.js emulation, excluding core node.js modules(path, util...) from the bundle. This may be used to create bundles targeted at node.js. (While this will not be a very common case, it can be used for example to distribute node.js apps as a single javascript file containing all dependencies).
    • verbose: Same as cli.
    • ignoreMissing: Same as cli.
    • minify: Same as cli.
    • compress: Same as cli.
    • output: Name of the output file. The file will not be written, this is used when building the source map.
    • sourceMap: Same as cli. This may be true to make the source map have the same name as 'output' with '.map' appended.
    • inlineSourceMap: Same as cli.
    • inlineSources: Same as cli.
    • npmSourceMaps: Same as cli. This is disabled by default because it greatly increases build efficiency and normally you wont care about debugging external modules.

Grunt task

This package includes a grunt task that takes any of the API or cli options( with dashes removed and converted to camelCase). For an example see this package's test bundle configuration

Examples

CLI example

Say we have the following directory tree:

* todos/
  * components/
    * users/
      - model.coffee
    * todos/
      - index.coffee
  * public/
    * javascripts/

Running the following command will export index.coffee and its dependencies as App.Todos.

powerbuild -o public/javascripts/app.js -x App.Todos -r components components/todos/index.coffee

Since the above command specifies components as the root directory for unqualified requires, we are able to require components/users/model.coffee with require 'users/model'. The output file will be public/javascripts/app.js.

Node Module Example

opts.root = 'components'
opts.entryPoints = ['index.coffee']
powerbuild = new Powerbuild opts
{code, map} = powerbuild.bundle()

changelog

v0.9.4 (2013-09-15)

  • 7d969b72: fixes #81: improve documentation for aliasing
  • 58fc9a7c: update dependency versions
  • 65819399: remove some unnecessary parentheses
  • 0f77e4d2: fixes #78: fix path canonicalisation and some erroneous tests
  • 1e0ef697: rebuild with new CoffeeScript compiler version

v0.9.3 (2013-08-30)

  • 046da017: Version 0.9.3
  • 0343e4f4: update coffee-script-redux to version 2.0.0-beta7
  • f9201f47: move CHANGELOG generation from ruby gem to shell script

v0.9.2 (2013-07-20)

  • 584005c2: Version 0.9.2
  • a788c6b1: loosen up querystring requirement
  • 68470d1a: fixes #73: support constants core module using constants-browserify
  • 6c3cc71f: remove erroneous .js from underscore-prefixed node core module listings
  • afae2e7c: protect against changes of main module in dependencies
  • c9164cb5: add more compatible punycode implementation

v0.9.1 (2013-07-17)

  • 048f829c: Version 0.9.1
  • 268477ad: update to isaacs/nopt@2.1.2 to support - as stdin representation again

v0.9.0 (2013-07-15)

  • cd51af47: Version 0.9.0
  • 30db2bc2: upgrade node to v0.10.13
  • 81156f3b: upgrade CoffeeScriptRedux to version 2.0.0-beta6

v0.8.1 (2013-07-15)

  • 84e370bf: Version 0.8.1
  • ab4f403e: a bit of a restructuring of the dependency resolution functions
  • 9efc3fc9: add some aliasing tests
  • 3b67b970: rebuild parent commit
  • bb05a791: use new escodegen.FORMAT_MINIFY constant
  • 0b787588: link to isaacs/nopt#20 instead of b8101f920e7bdcf758f97ba9b17c7d0422d67992
  • a5dcc310: more succinct option specification
  • 92315a5f: switch from michaelficarra/Jedediah to isaacs/nopt

v0.8.0 (2013-06-27)

  • 8f61bf5b: Version 0.8.0
  • 582fa43b: Merge branch 'new-sourceMappingURL-pragma'
  • 0e0f2546: fixes #64: add CLI option for extension handlers
  • d6dad8c7: fixes #34: allow handlers to return JS strings
  • 666b45e2: fixes #71: allow empty alias targets
  • 83765f72: change sourceMappingURL pragma to new //# format

v0.7.3 (2013-06-22)

  • fab9d809: Version 0.7.3
  • 86629c13: add newline to end of package.json in release tasks
  • 9c798593: fixes #28: add CLI option to specify aliases
  • 95f29212: nicer handling of !=1 entry point error

v0.7.2 (2013-06-03)

  • 1633449a: Version 0.7.2
  • c94ec2f2: fixes #69: normalise windows/unix paths during canonicalisation
  • 84a590af: fixes #66: add --inline-source-map option to include map as data URI
  • 69f68622: fixes #33: add --inline-sources flag to include source content in map
  • fd354a6b: recompile with CoffeeScriptRedux 2.0.0-beta5
  • b1c15f4b: clean up lib/index.js; moved to lib/module.js

v0.7.1 (2013-05-14)

  • 2291ffa7: Version 0.7.1
  • cfb65476: release-X targets now update CHANGELOG
  • b4d7d12d: release-{patch,minor,major} make targets now update changelog
  • a0d69620: fixes #62: improve logging in watch mode
  • a40025fb: Merge pull request #61 from krisnye/master
  • 09a1cf44: Making curr.ino? check platform specific to win32
  • ae64c225: fix CoffeeScriptRedux version to 2.0.0-beta5
  • f864c043: Fix -w option to work on windows
  • 82562ea4: some minor documentation updates regarding watch and source-map options
  • ebd855f2: fixes #56: add a changelog
  • 1ff7b178: Merge pull request #54 from Nami-Doc/master
  • a317399f: silence makefile

v0.7.0 (2013-04-27)

  • 13edd235: Version 0.7.0
  • 84923100: remove leftover (sync)s in test suite descriptors
  • 77d40f34: move test/_setup.coffee to test-setup.coffee
  • 8874a177: fixes #53: modularisation
  • 91735b73: fixes #49: de-duplicate src/index.coffee by removing async interface
  • 406b8271: add CLI --version flag; I can't believe I didn't already add this
  • 733ff9ca: change --source-map-file option to --source-map; add -s alias
  • 4c965b56: fixes #50: sourceMappingURL should be relative to output file if given

v0.6.3 (2013-04-25)

  • 5464c5e8: Version 0.6.3
  • a35ed96a: fixes #48: clean up output from syntax errors thrown by esprima

v0.6.2 (2013-04-21)

  • 23761b57: Version 0.6.2
  • 1425b3c3: fixes #44: CLI no longer stops building when errors occur while watching
  • bf8f3f7e: fixes #45: implement cache option for traverseDependencies
  • 9917fc61: only include comments in generated output when not minifying
  • cf602393: add leading "generated by" comment; refs substack/node-browserify#380
  • 03921196: slightly cleaner process.nextTick test
  • 12b064df: add tests for process.nextTick
  • fcf9c1a9: process.nextTick uses setImmediate if available

v0.6.1 (2013-04-05)

  • 55e884c6: Version 0.6.1
  • 61a16a34: re-ignore node submodule

v0.6.0 (2013-04-05)

  • a4314951: Version 0.6.0
  • 0a515514: fixes #41: add --deps flag to CLI; lists dependencies without bundling
  • 210ae5f7: fix error messages for unported node core modules
  • 823c19e8: fixes #39: core module symlinks are not packaged properly by npm
  • ac3b58d8: fixes #36: allow process stub to be omitted
  • c95f10f4: update README demo for sync/async interface
  • 80f4af68: add safety checks around release build targets

v0.5.1 (2013-03-31)

  • d1a7ddb8: Version 0.5.1
  • 7913adb2: use . as sourceMapRoot when source map is generated in root directory
  • f6b2efd6: use relative paths for sourceMapRoot value in source maps; closes #37
  • f92ca08f: fixes #32: support accepting entry point over stdin
  • bebf9cc4: .travis.yml indentation
  • 99f72145: Merge pull request #35 from ghempton/events
  • e5d2b099: support for 'events' core module
  • 55192c9c: add watch (and terse flags) example to readme

v0.5.0 (2013-03-21)

  • 19c5af84: Version 0.5.0
  • 338dbd3e: document --watch
  • 2a0562e7: update travis specification to use strings for versions
  • 41eadc44: switch --watch from fs.watch to more appropriate fs.watchFile
  • 7ad8239e: fixes #31: add --watch flag to CLI for continuous builds on dep changes
  • 71bdfb2c: move entryPoint canonicalisation into bundling function
  • 8ef53183: undefined core modules now produce an error by default
  • ced85bc2: index processed hash by filename instead of canonical name; refs #31
  • fc51af83: add core dependency resolution test
  • 27f4d49a: succinctly specify test files while still hopefully keeping Travis happy
  • 476f0b3b: add "bundle" to package.json keywords

v0.4.0 (2013-03-20)

  • c787513a: Version 0.4.0
  • cbc018e4: document async bundling interface
  • 4f1f97cc: switch worklist entries from ordered pairs to objects
  • b1e95f5e: implement traverseDependencies
  • 6ce6db16: move "TODO: async" to traverseDependencies, where it belongs for now
  • 2a52714e: start Travis testing against node 0.10.x
  • 3b9fe5b2: one last attempt to get Travis running tests properly
  • 67ba7757: glob tests so (hopefully) Travis once again passes
  • e5dec44c: allow core libraries in bundle to appear with the core library name
  • c3d2b4c0: test naming/organisation
  • 15e05b11: update joyent/node submodule to v0.10.0
  • cccb8c3e: add some tests for node core libraries
  • 5a797eb7: DRY the tests a bit
  • 4bc7f0ea: add tests for process.argv and process.env
  • 247b0e39: implement process.chdir; test process.cwd and process.chdir
  • f226c98f: add process.version support
  • e230ddb6: add basic process tests
  • 5e5b4b05: add async tests for the last 2 commits
  • 51796592: support module.children
  • d90a6b3d: support module.parent; based on substack/node-browserify#323
  • 70ca7a79: round out tests for traverseDependenciesSync
  • 2893951d: a few more tests for #31; more to come
  • 1da8d4b4: fixes #31: split out and expose dependency traversal
  • 18800f4e: add async bundling tests
  • 8f6e98aa: start adding async interface; ref #17
  • 1f9be258: PHONY the appropriate make targets
  • 5006cd63: add release tasks
  • f476442a: remove accidental mutation of given options object

v0.3.5 (2013-03-08)

  • 25a9c72f: Version 0.3.5
  • 5b3f660d: JS => Node Module
  • 07e5c8f1: fixes #19: add ignoreMissing option
  • e7959ec1: fixes #29: export helpers iff we're in a testing environment
  • 3e380ff1: add 0.9.x to supported engines since we're running it through travis
  • 56fa6ff6: Merge pull request #27 from poulejapon/patch-1
  • ac2ca854: add module caching test
  • 3d45d7a9: add circular dependency test
  • 82ccb726: Fixed travis' node versions.
  • c4f893b5: fixes #24: use a single process instance
  • 0232a453: fixes #6: add basic bundling tests; obviously still need to expand them
  • 325f1df9: small test cleanup
  • b6784bdb: start generating fixtures for tests; starts progress on #6
  • 2353fffc: Merge pull request #26 from poulejapon/852c83d6eb026fe3be70c0e706d3ef91e7178d08
  • 852c83d6: Added travis settings.

v0.3.4 (2013-03-03)

  • 33bc2330: Version 0.3.4
  • 70476f1d: fixes #23: support circular dependencies

v0.3.3 (2013-03-03)

  • bafdec55: Version 0.3.3
  • c601a3e0: fixes #21 for real: small tweaks to .npmignore

v0.3.2 (2013-03-03)

  • 68821870: Version 0.3.2
  • 81f6c6b8: fixes #21: add .npmignore to reduce package size
  • 0623dbb2: switch to more familiar top-level IIFE style using simple parens

v0.3.1 (2013-03-02)

  • 9838cf29: Version 0.3.1
  • 1f06ea30: fixes #20: implement badRequireError
  • 472abd07: replace AST literals with esprima.parse + mutations
  • c2e65bd5: fixes #16: modularise and clean up src/index.coffee
  • b01eb1cb: fixes #18: add a verbose option and a --verbose flag
  • 62045c9d: switch more git submodules to npm packages and change associated links
  • 466dccf8: fixes #5: use browserify-http as a dependency instead of a submodule
  • 93f3c9af: fill in package.json
  • 6a3cd299: add BSD license
  • 64caf5e2: delete unnecessary gitignore file; put these in your global gitignore

v0.3.0 (2013-02-28)

  • 83b91485: Version 0.3.0
  • 09624819: Merge pull request #14 from benjreinhart/master
  • f7e54478: fixes #15: require the entry point module even if not exported
  • e4006bab: Some dumbass mispelled cjsify
  • c77dbf6d: Merge pull request #10 from benjreinhart/nested-exports
  • 79e45653: Support nested objects
  • 77802dce: Merge pull request #12 from Nami-Doc/patch-1
  • 584e31c2: document handler second argument
  • 7ce2f7c9: Merge pull request #8 from benjreinhart/master
  • 080bbd35: Fixing -r option
  • c4c16cef: Merge branch 'master' of github.com:michaelficarra/commonjs-everywhere
  • 0934714c: documentation cleanup
  • fd0d62c3: Version 0.2.0
  • f13ea232: use coffee-script-redux master to avoid a recently patched bug
  • da09579c: pass around extensions in order to properly support custom handlers
  • 4a7e57db: add some documentation to the README

v0.2.0 (2013-02-24)

  • f48bfa76: Version 0.2.0
  • b3891d66: use coffee-script-redux master to avoid a recently patched bug
  • 85fc3b2b: pass around extensions in order to properly support custom handlers
  • 0ece9d17: add querystring shim
  • 1a700c95: better errors for unfound modules
  • c05ed7c7: support requiring from required symlinks
  • 8c676d6c: use resolvePath for alias resolution to allow flexible specification

v0.1.1 (2013-02-23)

  • 2f5205e7: version 0.1.1
  • 916c8577: add crypto, http, and vm node core modules
  • d5d8f4d1: Merge branch 'master' of github.com:michaelficarra/commonjs-everywhere
  • 7ea6be07: Merge pull request #4 from benjreinhart/master
  • 3b28ac5e: Mutate entryPoint to be resolved path
  • b9428da4: process.cwd()
  • 075cc9b7: Compute correct path when given root option
  • 671d5fab: add symlinks to node core libraries that work as-is in the browser
  • c80f12b9: Merge pull request #2 from benjreinhart/master
  • d0aef9c2: Minimal Readme

v0.1.0 (2013-02-23)

  • 2644cda8: add source map support, fix minification, change interfaces, 0.1.0
  • bf6052a8: add --minify flag and integrate with esmangle
  • 9d4c2193: rename bin/build to bin/cjsify
  • 77240e10: add --help flag
  • 24f3a9cf: documentation note
  • ef3c0f2e: update jedediah dependency to 0.1.0
  • 33dc2ce5: fix repo URL
  • 89311ab3: Merge pull request #1 from EndangeredMassa/smassa/dependency-update
  • 516ab74b: added .gitignore
  • 7c9743b1: updated package.json with jedediah dependency
  • 29b13ea6: initial commit