Webpack 5 comes with terser-webpack-plugin out of the box, hence you can just import it and configure as you wish.
» npm install uglifyjs-webpack-plugin
Webpack 5 comes with terser-webpack-plugin out of the box, hence you can just import it and configure as you wish.
As Sam said, Webpack 5 comes with the Terser plugin which does what UglifyJS used to do. Here's an example on how to use the Terser plugin for webpack.
// webpack.config.js
const TerserPlugin = require("terser-webpack-plugin");
const config = {
...
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(),
],
}
};
» npm install webpack-uglify-js-plugin
Webpack 4 does optimization and minification by default in production mode.
So if my guess is right, your configuration is development configuration.
You can remove your explicit UglifyJsPlugin definition and set the mode to production and Webpack will take care of everything.
mode: 'production',
plugins: [...],
optimization: ...
You can customize your optimizations though if you must. But setting the mode to production will yield you your expected results.
More info here
Webpack 4 mode usage
I was also facing the same issue. It started working after providing mode config value as production.
module.exports = {
// webpack config
mode: process.env.NODE_ENV || 'development',
};
// command NODE_ENV=production webpack
» npm install @sandfox/uglifyjs-webpack-plugin
» npm install uglifyjs-3-webpack-plugin