Webpack use UglifyJSPlugin to ONLY remove comments

Viewed 9393

I would like to use the Webpack UglifyJSPlugin to only remove comments from my bundle. I currently have the following UglifyJSPlugin configuration:

webpackPlugins = [
    new DedupePlugin(),
    new UglifyJsPlugin({
        compress: false,
        minimize: false,
        outputs: {
            comments: false
        }
    })
]

However, this still seems to minify the entire bundle. Is there another option to remove comments I am not taking advantage of? Is there a way to do this properly with UglifyJSPlugin?

4 Answers

This is what you need:

new UglifyJsPlugin({
    comments: false,
}),

Webpack 5 now has a slightly different config file:

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

module.exports = {
    optimization: {
        minimizer: [
            new UglifyJsPlugin({
                uglifyOptions: {
                    output: {
                        comments: false,
                        beautify: true,
                    },
                    mangle: false,
                    compress: false
                },
            }),
        ],
    },
    ...
}

UglifyjsWebpackPlugin Docs

Related