Webpack v5 comes with the latest terser-webpack-plugin out of the box (no need to install it).
Running webpack in production mode will enable minification by default.
To remove console.log()
statements add drop_console
to terserOptions
.
Use css-minimizer-webpack-plugin to minify and remove duplicates css.
optimization: {
minimizer: [
// Tells webpack@5 to extend defaults minimizer options
`...`,
new CssMinimizerPlugin()
]
}
This config will enable css optimization only in production mode.
Use HtmlWebpackPlugin.minify
to minimize html.
To enable minification in development set optimization.minimize: true
.
You can override the default minimizer with optimization.minimizer
option.
Source maps like eval
don't work with minimizer enable.