webpack-production-console-filter v1.0.1
Here’s a complete README.md for your webpack-production-console-filter package:
webpack-production-console-filter
A Webpack configuration extension that conditionally removes console.log statements in production builds. The logs are automatically removed unless the environment variable RETAIN_CONSOLE_LOGS is set to 'true'.
Installation
To use this package, first install it along with webpack-merge (if not already installed):
npm install webpack-production-console-filter webpack-merge --save-devUsage
To integrate the webpack-production-console-filter into your Webpack configuration, merge it into your existing Webpack configuration using webpack-merge.
Example webpack.config.js:
const merge = require('webpack-merge');
const productionConsoleFilter = require('webpack-production-console-filter');
const baseConfig = require('./webpack.config.base');
module.exports = merge(baseConfig, productionConsoleFilter());Environment Variables
This extension relies on the following environment variables:
NODE_ENV: Set this to'production'to enable the removal ofconsole.logstatements.RETAIN_CONSOLE_LOGS: Set this to'true'to retainconsole.logstatements in production builds.
Example Scenarios
Production build without console logs:
NODE_ENV=production npm run buildThis will remove all
console.logstatements from the production build.Production build retaining console logs:
NODE_ENV=production RETAIN_CONSOLE_LOGS=true npm run buildIn this case,
console.logstatements will be retained in the production build.Development build:
npm run devWhen
NODE_ENVis not set to'production', the console logs will always be retained.
Why Use webpack-production-console-filter?
This package simplifies the process of controlling console.log statements in your production builds. By using environment variables, you can easily toggle whether console logs are included in the final build, reducing file sizes and improving performance when needed.
License
This project is licensed under the MIT License.