javascriptnode.jswebpackuglifyjsuglifyjs-webpack-plugin

Use uglifyjs-webpack-plugin in `plugins` or in `minimizer` section of Webpack config?


When using the uglifyjs-webpack-plugin in your Webpack config files, should the plugin be used in the plugin section (based on this article) as showed in the first webpack config below?

Or in the minimizer section, as shown in the second webpack config (based on uglifyjs-webpack-plugin docs)?

Using webpack@4.39.1, uglifyjs-webpack-plugin@2.2.0, node@12.6.0

webpack config #1

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    plugins: [
        new UglifyJsPlugin(),
    }),
    ...

webpack config #2

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    optimization: {
        minimizer: [
            new UglifyJsPlugin()
        ]
    }
    ...

Solution

  • With the latest version of web pack(i.e > 4), it is sufficient if you include only in optimization: {minimizer: [] } section