webpack-production-console-filter
v1.0.1
Published
A Webpack configuration extension that removes console logs in production builds unless specified otherwise.
Downloads
8
Maintainers
Readme
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-dev
Usage
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.log
statements.RETAIN_CONSOLE_LOGS
: Set this to'true'
to retainconsole.log
statements in production builds.
Example Scenarios
Production build without console logs:
NODE_ENV=production npm run build
This will remove all
console.log
statements from the production build.Production build retaining console logs:
NODE_ENV=production RETAIN_CONSOLE_LOGS=true npm run build
In this case,
console.log
statements will be retained in the production build.Development build:
npm run dev
When
NODE_ENV
is 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.