This plugin build an extra JavaScript for ESModules, it supports loading with <script type="module" src="..."></script>
.
To begin, you'll need to install esmodules-webpack-plugin
:
$ npm install esmodules-webpack-plugin --save-dev
Then add the plugin to your webpack
config. For example:
webpack.config.js
const ESModulesWebpackPlugin = require('esmodules-webpack-plugin');
module.exports = {
plugins: [
new ESModulesWebpackPlugin()
]
};
And run webpack
via your preferred method.
- Build completely different files for both modern and legacy browsers
- Avoid rebuilding the assets except JavaScript
- Support html-webpack-plugin and inject scripts automatically
- ...
- Type:
Object
- Required:
false
Compile JavaScript for ESModules with this config, the plugin will inject any assets exclude .js
that you compiled before, so we won't build assets twice.
tips: If webpackConfig
is defined, webpackOptions
will be ignored.
- Type:
Object
- Required:
false
It also a webpackConfig for ESModules, the difference is that it will merge the defaultConfig which is based on previous config, so it's flexible when you need to load some plugins or options.
- Type:
String|Boolean
- Required:
false
- default: development=true, production=false
If style-loader
was used, please let me know so we can deal with css
and inject css to js.