Converts global scripts into named System.registerDynamic('name', [], ...
In
foo = "bar";
Out
System.registerDynamic("foo", [], false, function ($__require, $__exports, $__module) {
var _retrieveGlobal = System.registry.get("@@global-helpers").prepareGlobal($__module.id, "foo", null);
(function ($__global) {
foo = "bar";
})(this);
return _retrieveGlobal();
});
$ npm install babel-plugin-transform-global-system-wrapper
.babelrc
{
"plugins": [
["transform-global-system-wrapper", {
"deps": ["baz.js"],
"exportName": "foo",
"globals": {
"jquery": "jquery.js"
},
"moduleName": "foo",
"systemGlobal": "SystemJS"
}]
]
}
$ babel --plugins transform-global-system-wrapper script.js
require("babel-core").transform("code", {
plugins: [
["transform-global-system-wrapper", {
deps: ["baz.js"],
exportName: "foo",
globals: {
"jquery": "jquery.js"
},
moduleName: "foo",
systemGlobal: "SystemJS",
esModule: true
}]
]
});