BTC
BTC

Reputation: 4062

Webpack use UglifyJSPlugin to ONLY remove comments

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?

Upvotes: 6

Views: 10546

Answers (4)

bordeaux
bordeaux

Reputation: 353

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

Upvotes: 1

xiao
xiao

Reputation: 1758

Using webpack 2, the settings below worked for me.

new webpack.optimize.UglifyJsPlugin({
  output: {
    comments: false,
    beautify: true,
  },
  mangle: false,
  compress: false,
}),

Upvotes: 4

geniuscarrier
geniuscarrier

Reputation: 4239

This is what you need:

new UglifyJsPlugin({
    comments: false,
}),

Upvotes: 9

ericornelissen
ericornelissen

Reputation: 171

What you're looking for is probably "beautify" combined with "mangle".

"Beautify" will output indented code instead of a one-line file, so you want this to be true. "mangle" will make your code as short as possible (e.g. by abbreviating variable names), so you want this to be false.

For more info about these two options see the UglifyJS README

webpackPlugins = [
    new DedupePlugin(),
    new UglifyJsPlugin({
        beautify: true,
        mangle: false
    })
]

Upvotes: 2

Related Questions