babel-plugin-dynamic-import-node

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

MIT 12 个版本
安装
npm install babel-plugin-dynamic-import-node
yarn add babel-plugin-dynamic-import-node
pnpm add babel-plugin-dynamic-import-node
bun add 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*/
  });
版本列表
2.3.3 2020-04-21
2.3.2 2020-04-20
2.3.1 2020-04-20
2.3.0 2019-06-18
2.2.0 2018-10-08
2.1.0 2018-08-29
2.0.0 2018-06-26
1.2.0 2017-11-13
1.1.0 2017-09-11
1.0.2 2017-05-05
1.0.1 2017-03-18
1.0.0 2016-11-11