This will help you to remove console.log and comments from typescript or javascript files using webpack 4
webpack remove console.log
npm i npm install uglifyjs-webpack-plugin --save-dev
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const optimization = {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
output: {
// removing comments
comments: false,
},
compress: {
// remove warnings
warnings: false,
// remove console.logs
drop_console: true,
},
},
}),
],
};
module.exports = optimization;
Add optimization here.
const optimization = require('../webpack-optimization.config');
module.exports = {
...
optimization
}
npm i uglifyjs-webpack-plugin -D
insteadnpm i npm install uglifyjs-webpack-plugin --save-dev