Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 2.82 KB

README.md

File metadata and controls

58 lines (43 loc) · 2.82 KB

pure-cjs

Pure CommonJS Modules builder.

Features

  • 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 in node_modules hierarchy.
  • Does not corrupt require('systemModule') calls, transforms only local ones.

Console usage

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)

Usage from Node.js

var cjs = require('pure-cjs');

cjs.transform(options).then(function (result) {
    // handle successful result
}, function (err) {
	// handle error
});

Options object

  • 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; if true is provided, path default to function (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 to true, doesn't write output to disk.

Result object

  • code: String — generated source code.
  • map: Object — source map object.
  • options: Object — options object with resolved defaults and paths.

Usage from Grunt

Check out grunt-pure-cjs to use builder as Grunt plugin.