@babel/plugin-transform-modules-systemjs

NOTE: This plugin is included in @babel/preset-env under the modules option

This plugin transforms ECMAScript modules to SystemJS. Note that only the syntax of import/export statements (import "./mod.js") and import expressions (import('./mod.js')) is transformed, as Babel is unaware of different resolution algorithms between implementations of ECMAScript modules and SystemJS.

Example

In

  1. export default 42;

Out

  1. System.register([], function(_export, _context) {
  2. return {
  3. setters: [],
  4. execute: function() {
  5. _export("default", 42);
  6. },
  7. };
  8. });

For dynamic import support (import('./lazy.js').then(m => ...)), enable the @babel/plugin-syntax-dynamic-import plugin before this one.

Installation

  1. npm install --save-dev @babel/plugin-transform-modules-systemjs

Usage

Without options:

  1. {
  2. "plugins": ["@babel/plugin-transform-modules-systemjs"]
  3. }

With options:

  1. {
  2. "plugins": [
  3. [
  4. "@babel/plugin-transform-modules-systemjs",
  5. {
  6. // outputs SystemJS.register(...)
  7. "systemGlobal": "SystemJS"
  8. }
  9. ]
  10. ]
  11. }

Via CLI

  1. babel --plugins @babel/plugin-transform-modules-systemjs script.js

Via Node API

  1. require("@babel/core").transformSync("code", {
  2. plugins: ["@babel/plugin-transform-modules-systemjs"],
  3. });