Napping Panda Missionaries

    babel-plugin-transform-import-commonjs

    1.0.0 • Public • Published

    babel-plugin-transform-import-commonjs

    Fork of https://github.com/kiurchv/babel-plugin-transform-system-import-commonjs that compiles import instead of System.import, now that the import() proposal has been accepted.

    Babel plugin that transforms ES2015 import into CommonJS require.

    https://github.com/tc39/proposal-dynamic-import

    How this works

    This plugin transforms

    var myModule = "./path/to/myModule";
     
    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-import-commonjs

    Usage

    Via .babelrc (Recommended)

    .babelrc

    {
      "plugins": ["transform-import-commonjs"]
    }

    Via CLI

    $ babel --plugins transform-import-commonjs script.js

    Via Node API

    require("babel-core").transform("code", {
      plugins: ["transform-import-commonjs"]
    });

    Install

    npm i babel-plugin-transform-import-commonjs

    DownloadsWeekly Downloads

    2,323

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • pwmckenna