A few seconds.

babel-plugin-transform-cjs-system-wrapper

Wraps CommonJS scripts into System.registerDynamic(...

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"],
      "globals": {
        "f": "foo"
      }
    }]
  ]
}

Via CLI

$ babel --plugins transform-cjs-system-wrapper script.js
require("babel-core").transform("code", {
  moduleId: 'foobar', // optional (default: '')
  plugins: [
    ["transform-cjs-system-wrapper", {
      requireName: 'require' // (default: 'require')
      systemGlobal: "SystemJS", // optional (default: 'SystemJS')
      path: "/path/to/foobar", // optional (default: '')
      optimize: true, // optional (default: false)
      static: true, // optional (default: false)
      deps: ['bar'], // optional (default: []),
      map: function(dep) {
        return mappedDep
      }, // (default: identity)
      globals: {  // optional (default: {})
        f: foo
      }
    }]
  ]
});
Pincer is a project which aims to provide best library discovery tools for developers. We're growing day by day. We have only npm platform for now but we will add the others as much as we can.