babel-plugin-transform-system-import-commonjs
v1.0.3
Published
Transform ES2015 System.import to CommonJS require
Maintainers
Readme
babel-plugin-transform-system-import-commonjs
Babel plugin that transforms ES2015 System.import into CommonJS require.
Deprecation notice
** Since import() proposal was accepted, System.import function now is obsolete and this plugin is not recommended to use in new projects. Please use import() function with babel-plugin-transform-import-commonjs instead. **
How this works
This plugin transforms
var myModule = "./path/to/myModule";
System.import(myModule).then(function (module) {
console.log(module);
});to
var myModule = "./path/to/myModule";
new Promise(function(resolve) {
resolve(require(myModule));
}.bind(this)).then(function (module) {
console.log(module);
});Requirements
You need support for Promise, use polyfill if needed.
Installation
$ npm install babel-plugin-transform-system-import-commonjsUsage
Via .babelrc (Recommended)
.babelrc
{
"plugins": ["transform-system-import-commonjs"]
}Via CLI
$ babel --plugins transform-system-import-commonjs script.jsVia Node API
require("babel-core").transform("code", {
plugins: ["transform-system-import-commonjs"]
});