I am running npm run build command and I am expecting it to minify my jss and css files which does but the code is still spread over multiple line and including comments. How to tell webpack to compress it to single line and remove comments?
this is how build command looks into package.json
"build": "npm run buildsprite && webpack --config ./webpack/webpack.config.prod.js --colors",
this is optimization chunk from webpack.config.prod.js
optimization: {
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
cache: true,
parallel: true,
sourceMap: true,
extractComments: false,
}),
],
},
As per the Documentation, your webpack.config.prod.js should look something like this:
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
cache: true,
parallel: true,
sourceMap: true,
extractComments: false,
}),
],
},
You Need minimize: true so that webpack can actually Minify using Terser