Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmithdev/77b80735e6a943eda42f703eed1d7977 to your computer and use it in GitHub Desktop.
Save jsmithdev/77b80735e6a943eda42f703eed1d7977 to your computer and use it in GitHub Desktop.
remove console.log & comments from code webpack

Remove Console Log From Prod Bundle using Webpack

This will help you to remove console.log and comments from typescript or javascript files using webpack 4

Install uglifyjs-webpack-plugin

webpack remove console.log

npm i npm install uglifyjs-webpack-plugin --save-dev

create bs-module-app\webpack\webpack-optimization.config.js

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;

Go to webpack.config.js

Add optimization here.

const optimization = require('../webpack-optimization.config');

module.exports = {
  ...
  optimization
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment