1.0.1 • Published 10 months ago

webpack-production-console-filter v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

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 of console.log statements.
  • RETAIN_CONSOLE_LOGS: Set this to 'true' to retain console.log statements in production builds.

Example Scenarios

  1. Production build without console logs:

    NODE_ENV=production npm run build

    This will remove all console.log statements from the production build.

  2. 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.

  3. 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.

1.0.1

10 months ago

1.0.0

10 months ago