Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Converts global scripts into named System.registerDynamic('name', [], ...

License

Notifications You must be signed in to change notification settings

systemjs/babel-plugin-transform-global-system-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 30, 2017
bfa9de6 · May 30, 2017

History

30 Commits
May 30, 2017
May 30, 2017
Jul 23, 2016
Jul 23, 2016
Jul 23, 2016
Jul 23, 2016
Jul 23, 2016
May 30, 2017
May 30, 2017

Repository files navigation

babel-plugin-transform-global-system-wrapper

Converts global scripts into named System.registerDynamic('name', [], ...

Example

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();
});

Installation

$ npm install babel-plugin-transform-global-system-wrapper

Usage

Via .babelrc

.babelrc

{
  "plugins": [
    ["transform-global-system-wrapper", {
      "deps": ["baz.js"],
      "exportName": "foo",
      "globals": {
        "jquery": "jquery.js"
      },
      "moduleName": "foo",
      "systemGlobal": "SystemJS"
    }]
  ]
}

Via CLI

$ babel --plugins transform-global-system-wrapper script.js

Via Node API (Recommended)

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
    }]
  ]
});