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?
This is what you need:
new UglifyJsPlugin({
comments: false,
}),
Using webpack 2, the settings below worked for me.
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false,
beautify: true,
},
mangle: false,
compress: false,
}),
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
})
]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With