babel-plugin-dynamic-import-amd

Babel plugin to transpile import() to require, for AMD module loaders

Usage no npm install needed!

<script type="module">
  import babelPluginDynamicImportAmd from 'https://cdn.skypack.dev/babel-plugin-dynamic-import-amd';
</script>

README

babel-plugin-dynamic-import-amd

Babel plugin to transpile import() to require, for AMD module loaders

NOTE: Babylon v6.12.0 is required to correctly parse dynamic imports.

Build Status

Installation

$ npm install babel-plugin-dynamic-import-amd --save-dev

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["dynamic-import-amd"]
}

Via CLI

$ babel --plugins dynamic-import-amd script.js

Via Node API

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

Syntax

Now just use syntax from the proposal for adding a "function-like" import() module loading syntactic form to JavaScript. It is currently in stage 3 of the TC39 process.

import('module-name');

let name = '-name';
import(`module-${name}`);

Credits

Many credits go to AirBNB's package babel-plugin-dynamic-import-webpack. This package contains the same tests as that library. And it formed the base for the actual dynamic import implementation.