babel-plugin-transform-cjs-system-wrapper
Wraps CommonJS scripts into System.registerDynamic(...
Example
In
'use strict';
var foo = require('foo/');
Babel Options
{
moduleId: 'foobar'
plugins: [
['transform-cjs-system-wrapper', {
deps: ['bar'],
globals: {
f: foo
}
}]
]
}
Out
System.registerDynamic('foobar', ['bar'], true, function ($__require, exports, module) {
'use strict';
var f = $__require('foo');
var global = this,
GLOBAL = this;
var foo = $__require('foo');
});
Installation
$ npm install babel-plugin-transform-cjs-system-wrapper
Usage
Via .babelrc
.babelrc
{
"moduleId": "foobar",
"plugins": [
["transform-cjs-system-wrapper", {
"systemGlobal": "SystemJS",
"path": "/path/to/foobar",
"optimize": true,
"static": true,
"deps": ["bar"],
"esModule": true,
"globals": {
"f": "foo"
}
}]
]
}
Via CLI
$ babel --plugins transform-cjs-system-wrapper script.js
Via Node API (Recommended)
require("babel-core").transform("code", {
moduleId: 'foobar',
plugins: [
["transform-cjs-system-wrapper", {
requireName: 'require'
systemGlobal: "SystemJS",
path: "/path/to/foobar",
optimize: true,
static: true,
deps: ['bar'],
esModule: true,
map: function(dep) {
return mappedDep
},
globals: {
f: foo
}
}]
]
});