Webpack Clear Console

raw JSON →
1.0.3 verified Fri May 01 auth: no javascript

webpack-clear-console is a Webpack plugin that removes console statements from the bundle during compilation. Version 1.0.3 (latest) is stable with no recent updates. It provides a comment-based exclusion mechanism (/*NotClearConsole*/) to preserve specific console calls. Compared to similar plugins like babel-plugin-transform-remove-console or terser-webpack-plugin drop_console option, this plugin offers finer control per statement, though it only supports Webpack 4+ and requires manual comment annotations. No TypeScript types are included.

error TypeError: WebpackClearConsole is not a constructor
cause Importing the package without destructuring; using require('...') returns an object, not the constructor.
fix
Use const { WebpackClearConsole } = require('webpack-clear-console'); then new WebpackClearConsole();
error Module build failed: Error: Cannot find module 'webpack-clear-console'
cause Package not installed or npm link issue.
fix
Run npm install webpack-clear-console --save-dev
error console.log statements are not removed in production build
cause Plugin not added to plugins array or Webpack config mode not set to production.
fix
Add new WebpackClearConsole() to plugins array in webpack.config.js.
gotcha The comment /*NotClearConsole*/ must be placed on the same line as or immediately after the console statement to preserve it.
fix Add /*NotClearConsole*/ on the same line as console.log('keep me');.
gotcha Only statements that start with console. are removed. Member expressions like Array.prototype.console are not affected.
fix Ensure all console calls begin with console. to be removed.
gotcha Works only with Webpack 4+; plugin API may be incompatible with older Webpack versions.
fix Upgrade to Webpack 4 or later.
breaking The plugin removes all console calls regardless of severity (log, warn, error, etc.). There is no option to filter by console method.
fix If selective removal is needed, consider using a custom loader or babel-plugin-transform-remove-console.
deprecated The package has not been updated since 2018; Webpack 5 compatibility is not tested.
fix Test with Webpack 5; if broken, use an alternative like terser-webpack-plugin drop_console.
npm install webpack-clear-console
yarn add webpack-clear-console
pnpm add webpack-clear-console

Basic Webpack config that removes all console statements from the output bundle using WebpackClearConsole.

// webpack.config.js
const { WebpackClearConsole } = require('webpack-clear-console');

module.exports = {
  mode: 'production',
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: __dirname + '/dist',
  },
  plugins: [
    new WebpackClearConsole(),
  ],
};