简体   繁体   中英

UglifyJS and webpack v5

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

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

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(),
        ],
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM