broccoli-cjs-wrap
v0.0.6
Published
broccoli filter for wrapping CommonJS modules
Downloads
1,777
Maintainers
Readme
broccoli-cjs-wrap
Wrap naked CommonJS modules in a define
wrapper for use in browser.
Installation
npm install --save-dev broccoli-cjs-wrap
Usage (Sample Brocfile.js)
var cjsWrap = require('broccoli-cjs-wrap');
var filterEs6Module = require('broccoli-es6-module-filter');
var pickFiles = require('broccoli-static-compiler');
var mergeTrees = require('broccoli-merge-trees');
module.exports = function (broccoli) {
// in conjunction with es6 module filter
var tree = broccoli.makeTree('lib');
// create a CJS version
var cjsTree = filterEs6Module(pickFiles(tree, {
srcDir: '',
destDir: 'cjs'
}));
var wrappedCjsTree = cjsWrap(pickFiles(cjsTree, {
srcDir: '',
destDir: 'cjs-wrapped'
}));
return mergeTrees([cjsTree, wrappedCjsTree]);
};
To build:
$ broccoli build output
Options
namespace
- Namespace all your modules. ex: 'MyApp',MyApp/tracker
packageName
- Name of your package, goes after the namespace.main
- main entry point of the module. ex: 'index',MyApp/tracker/index.js
->MyApp/tracker
. You must pass apackageName
and/ornamespace
if you usemain
require
- Require function thatdefine
is attached to. Defaults tothis.require