A webpack plugin for injecting core-js polyfills based on your browserslist configuration.
This plugin is essentially a wrapper for core-js-builder for webpack.
One usecase is that you are not using babel, but esbuild for transpiling, e.g. using the ESBuildMinifyPlugin with your supported browsers is much faster then using Babel, but it only transpiles the syntax and does not add any polyfills. So you would need to add e.g. core-js polyfills manually... or... use this plugin.
This version should work with webpack 4 as well as with webpack 5.
npm i -D webpack-plugin-corejs
In your webpack.config.js
:
const CoreJSPlugin = require('webpack-plugin-corejs')
module.exports = {
//...
plugins: [
new CoreJSPlugin({
// Options
}),
// ...
]
// ...
}
Or in your webpack.config.mjs
:
import { CoreJSPlugin } from 'webpack-plugin-corejs'
export default {
//...
plugins: [
new CoreJSPlugin({
// Options
}),
// ...
]
// ...
}
All options are optionally, if no options are given the default is to use { modules: 'core-js/es' }
.
You can omit setting targets
in this case browserslist is used (package.json
or .browserslistrc
).
{
/** CoreJS modules to use, defaults to 'core-js/es' */
modules?: string | readonly string[] | readonly RegExp[],
/** CoreJS modules to exclude */
exclude?: string | readonly string[] | readonly RegExp[],
/** Overide browserslist targets */
targets?: string | readonly string[] | Record<string, string | readonly string[]>
/** Add comment which modules are used within bundle */
summary?: {
size: boolean
modules: boolean
}
}
See CHANGELOG