1.1.0 • Published 7 years ago

babel-plugin-webpack-named-dynamic-imports v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

babel-plugin-webpack-named-dynamic-imports Build Status

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
importModules('./a.js');

// named chunk w/ exactly 1 module
importModules('./a.js', 'named-chunk-1')

// unnamed chunk containing multiple modules
importModules([
    './a.js',
    './b.js'
])

// named chunk containing multiple modules
importModules([
    './a.js',
    './b.js'
], 'named-chunk-2')

The code above will be transpiled to the following:

import("./a.js");

import( /* webpackChunkName: "named-chunk-1" */"./a.js");

Promise.all([
    import("./a.js"),
    import("./b.js")
]);

Promise.all([
    import( /* webpackChunkName: "named-chunk-2" */"./a.js"),
    import( /* webpackChunkName: "named-chunk-2" */"./b.js")
]);