airbnb / Babel Plugin Dynamic Import Webpack
Licence: mit
Babel plugin to transpile import() to require.ensure, for Webpack
Stars: ✭ 488
Programming Languages
javascript
184084 projects - #8 most used programming language
babel-plugin-dynamic-import-webpack
Babel plugin to transpile import()
to require.ensure
, for Webpack.
Note that Webpack 2 has gotten import()
after this code was written.
NOTE: Babylon v6.12.0 is required to correctly parse dynamic imports.
Installation
$ npm install babel-plugin-dynamic-import-webpack --save-dev
Usage
.babelrc
(Recommended)
Via .babelrc
{
"plugins": ["dynamic-import-webpack"]
}
Via CLI
$ babel --plugins dynamic-import-webpack script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["dynamic-import-webpack"]
});
Dynamic imports and webpack
Although the specification for import()
supports a dynamic importing of modules in the browser runtime, webpack's require.ensure()
is not dynamic and requires a hardcoded string to work correctly. For more information see webpack's documentation on dynamic imports.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].