UglifyJS and webpack v5
Asked Answered
O

2

25

We've been using UglifyJS and webpack v4 for our react code, but then just updated to webpack v5. It appears that UglifyJS does not work with webpack v5. Is there an alternative? We need something that works with babel-loader.

Thanks

Opec answered 15/12, 2020 at 1:9 Comment(1)
webpack.js.org/plugins/terser-webpack-plugin You don't have to install Uglify plugin, it has inbild support in webpack 5Lema
S
30

Webpack 5 comes with terser-webpack-plugin out of the box, hence you can just import it and configure as you wish.

Sibell answered 15/12, 2020 at 4:9 Comment(1)
I want to remove all the consoles from bundle.will it do automatically?Geoffrey
D
19

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(),
        ],
    }
};
Dieppe answered 21/12, 2022 at 5:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.