Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-dynamic-import-node

airbnb16.4mMIT2.3.3

Babel plugin to transpile import() to a deferred require(), for node

babel, plugin, dynamic, import, node

readme

babel-plugin-dynamic-import-node

Babel plugin to transpile import() to a deferred require(), for node. Matches the proposed spec.

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

Installation

npm install babel-plugin-dynamic-import-node --save-dev

Usage

.babelrc

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

Options

  • noInterop - A boolean value, that if true will not interop the require calls. Useful to avoid using require('module').default on commonjs modules.
{
  "plugins": [
    ["dynamic-import-node", { "noInterop": true }]
  ]
}

Via CLI

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

Via Node API

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

Code Example

Promise.all([
  import('./lib/import1'),
  import('./lib/import2')
 ]).then(([
   Import1,
   Import2
  ]) => {
   console.log(Import1);
   /* CODE HERE*/
  });

changelog

Unreleased

v2.3.3

  • [Fix] Generate webpack-compatible output with static string arg (#84)
  • [Fix] Handle visiting the same path gracefully (#71)

v2.3.2

  • [Fix] avoid using reserved param name in babel 7 templates
  • [Dev Deps] update airbnb-js-shims

v2.3.1

  • [Fix] Evaluate import() argument synchronously (#85)
  • [Dev Deps] update eslint, eslint-config-airbnb-base, in-publish, rimraf, safe-publish-latest, tape

v2.3.0

  • [New] expose createDynamicImportTransform and getImportSource (#75)
  • [Docs] Document noInterop option (#70)

v2.2.0

  • [Refactor] remove dependency on babel-plugin-syntax-dynamic-import
  • [Dev Deps] update airbnb-js-shims, babel-preset-airbnb, eslint

v2.1.0

  • [New] add noInterop option (#57)
  • [Docs] Fix typo "correct" -> "correctly" in readme (#55)
  • [Dev Deps] update airbnb-js-shims, babel-eslint, babel-preset-airbnb, eslint, eslint-config-airbnb-base, eslint-plugin-import, safe-publish-latest

v2.0.0

  • [Breaking] always return a module namespace object (#52, #47)
  • [Breaking] remove .default on entry points (#27)
  • [Docs] removed $ before npm command (#35)
  • [Docs] Improve README.md with a code example (#41)
  • [Dev Deps] update airbnb-js-shims, babel-core, babel-eslint, eslint, eslint-plugin-import
  • [Tests] switch from mocha to tape, so we can support older nodes

v1.2.0

  • [New] support comments (#37)
  • [Refactor] Use template and types from the babel object (#32)
  • [Tests] on node v9; pin included builds to LTS
  • [Dev Deps] update eslint, eslint-config-airbnb-base, mocha, rimraf

v1.1.0

  • Visit Import nodes instead of CallExpressions (#30)
  • [Deps] update babel-template, babel-types
  • [Dev Deps] update airbnb-js-shims, babel-cli, babel-core, babel-preset-airbnb, babel-register, chai, eslint, eslint-config-airbnb-base, eslint-plugin-import, mocha
  • [Tests] on node v8
  • [Tests] use nvm install-latest-npm so newer npm doesn’t break older node

v1.0.2

  • [Fix] Ensure it works with the ES2015 preset too (#12, #16)
  • [Deps] update babel-template, babel-types
  • [Dev Deps] update babel-cli, babel-core, babel-eslint, babel-register, eslint, eslint-config-airbnb-base, mocha

v1.0.1

  • [Fix] Move in-publish to devDeps (#11)
  • [Fix] ensure dynamic import() input is properly stringified (#2)
  • [Fix] async timing of dynamic import to match spec (#3)
  • [Fix] Remove spaces in template strings and update Babel (#10)
  • [Deps] update babel-template, babel-types
  • [Deps] update babel-types (#4, #5, #6)
  • [Dev Deps] update babel-cli, babel-core, babel-eslint, babel-register, eslint, eslint-config-airbnb-base, eslint-plugin-import, mocha, rimraf

v1.0.0

  • Initial full release.