babel-plugin-webpack-named-dynamic-imports
A babel plugin which implements a better syntax for webpack@2+
dynamic imports.
Usage
Install the package:
npm i babel-plugin-webpack-named-dynamic-imports --save
And enable it in a babel config:
"plugins": "webpack-named-dynamic-imports"
Now you can use the following syntax to dynamically import modules:
// unnamed chunk w/ exactly 1 module; // named chunk w/ exactly 1 module // unnamed chunk containing multiple modules // named chunk containing multiple modules
The code above will be transpiled to the following:
import"./a.js"; import /* webpackChunkName: "named-chunk-1" */"./a.js"; Promiseall import"./a.js" import"./b.js"; Promiseall import /* webpackChunkName: "named-chunk-2" */"./a.js" import /* webpackChunkName: "named-chunk-2" */"./b.js";