https://github.com/RReverser/pure-cjs
Pure minimalistic CommonJS builder
https://github.com/RReverser/pure-cjs
Last synced: about 1 year ago
JSON representation
Pure minimalistic CommonJS builder
- Host: GitHub
- URL: https://github.com/RReverser/pure-cjs
- Owner: RReverser
- License: mit
- Created: 2013-12-03T23:37:46.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-05-26T16:19:37.000Z (about 11 years ago)
- Last Synced: 2025-04-15T12:50:21.799Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/pure-cjs
- Size: 538 KB
- Stars: 44
- Watchers: 10
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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)](http://requirejs.org/docs/whyamd.html#sugar) and most projects already match this).
* Ability to export `module.exports` from top module in [UMD](https://github.com/umdjs/umd) style (useful for building libs).
* Allows to use [through](https://github.com/dominictarr/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:
```bash
npm install -g pure-cjs
```
Command-line options:
```
-h, --help output usage information
-V, --version output the version number
-i, --input input file (required)
-o, --output output file (defaults to .out.js)
-m, --map file to store source map to (optional, defaults to .map)
-c, --comments preserve comments in output
-e, --exports top module exports destination (optional)
-x, --extension default extension for requires (defaults to "js")
-d, --module-dir modules directory name to look in (defaults to "node_modules")
-s, --external [hash] external modules (names or JSON hashes)
```
Example:
```bash
pure-cjs \
--input src/index.js \
--output dist/index.js \
--map \
--exports SuperLib \
--external lodash \
--external '{"jquery": {"global": "$", "amd": "../vendor/jquery.js"}}'
```
## Usage from Grunt
Check out [grunt-pure-cjs](https://github.com/RReverser/grunt-pure-cjs) to use builder as [Grunt](https://gruntjs.com/) plugin.
## Usage from Gulp
Check out [gulp-pure-cjs](https://github.com/parroit/gulp-pure-cjs) to use builder as [Gulp](http://gulpjs.com/) plugin.
## Usage from Node.js code
```javascript
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.
Default: `input => input.replace(/(\.js)?$/, '.out.js')`
* `map`: `Boolean` | `String` | `Function(input, output)`
Source map.
Default: `false` (don't generate source map).
* `comments`: `Boolean`
Preserve comments in output.
Default: `false`
* `external`: `{ cjsName: (true | { amd?: String, global?: String }) }`
External dependencies (to be excluded from bundling). Example:
```javascript
{
jquery: true,
lodash: {amd: '../vendor/lodash.js', global: '_'}
}
```
* `exports`: `String` | `Function(input, output)`
Export top module with [UMD](https://github.com/umdjs/umd) with given global object name.
Default: no exports.
* `transform`: `Array` | `Function(input)`
Browserify plugins ([through](https://github.com/dominictarr/through)-stream(s) to be used against input files).
* `moduleDir`: `String`
Modules directory name.
Default: `"node_modules"`
* `defaultExt`: `String`
Default extension for require calls (`"js"`).
* `dryRun`: `Boolean`
Don't write output to disk (and don't append `//# sourceMappingURL=...` to code).
Default: `false`
### Result object
* **code**: `String` — generated source code.
* **map**: `Object` — source map object.
* **options**: `Object` — options object with resolved defaults and paths.