Pure CommonJS Modules builder.
- Minimal destination overhead (almost as small as concatenated file).
- Resolves all the paths on build stage to static number identifiers (so saves space and execution time used for storing and resolving string paths, but should be used only for projects with static
require('./some/module')
calls and would fail on others (same restriction applicable for r.js (Simplified CommonJS wrapper) and most projects already match this). - Ability to export
module.exports
from top module in UMD style (useful for building libs). - Allows to use through-stream(s) for pre-transformations.
- Supports modules installed as
npm
dependencies innode_modules
hierarchy. - Does not corrupt
require('systemModule')
calls, transforms only local ones.
Installation:
npm install -g pure-cjs
Command-line options:
-h, --help output usage information
-V, --version output the version number
-i, --input <file> input file (required)
-o, --output <file> output file (defaults to <input>.out.js)
-m, --map <file> file to store source map to (optional, defaults to <output>.map)
-e, --exports <id> top module exports destination (optional)
var cjs = require('pure-cjs');
cjs.transform(options).then(function (result) {
// handle successful result
}, function (err) {
// handle error
});
- input:
String|Function()
— input file; example:'superLib/topModule.js'
. - output:
String|Function(input)
— output file; optional, defaults to:function (input) { return input.replace(/(\.js)?$/, '.out.js') }
. - map:
String|Function(input, output)|Boolean
— source map file; optional, doesn't generate source map by default; iftrue
is provided, path default tofunction (input, output) { return output + '.map' }
. - exports:
String|Function(input, output)
— Exports top module with UMD with given global object name; optional, doesn't wrap into UMD by default. - transform:
Array|Function(input)
— Array of or single function that returns transformation through-stream(s) to be used against input files before their usage; optional. - dryRun:
Boolean
— if set totrue
, doesn't write output to disk.
- code:
String
— generated source code. - map:
Object
— source map object. - options:
Object
— options object with resolved defaults and paths.
Check out grunt-pure-cjs to use builder as Grunt plugin.