npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-preset-production-console-filter

v1.0.0

Published

A Babel preset to conditionally remove console logs in production builds.

Downloads

9

Readme

Here’s a sample README.md file for your custom Babel preset:


babel-preset-production-console-filter

A simple Babel preset that conditionally removes console.* statements in production builds, with the option to retain console logs using an environment variable.

Installation

You can install this preset using npm or yarn:

npm install babel-preset-production-console-filter --save-dev

or

yarn add babel-preset-production-console-filter --dev

Usage

To use the preset in your project, add it to your Babel configuration file (babel.config.js or .babelrc.js):

babel.config.js Example

module.exports = {
  presets: [
    '@babel/preset-env',
    'production-console-filter',
  ],
};

How It Works

This preset will automatically add the babel-plugin-transform-remove-console plugin to your Babel configuration only when the following conditions are met:

  • The NODE_ENV environment variable is set to production.
  • The RETAIN_CONSOLE_LOGS environment variable is not set to 'true'.

If both conditions are true, console.* statements will be removed from the output. Otherwise, the logs will be retained.

Example Scenarios

  1. Production build without console logs:

    NODE_ENV=production npm run build

    In this case, the preset removes all console.* statements.

  2. Production build retaining console logs:

    NODE_ENV=production RETAIN_CONSOLE_LOGS=true npm run build

    Here, the preset does not remove any console.* statements due to the RETAIN_CONSOLE_LOGS environment variable.

  3. Development build:

    npm run dev

    When NODE_ENV is not set to production, console logs are always retained, regardless of the RETAIN_CONSOLE_LOGS setting.

Environment Variables

  • NODE_ENV: Set this to 'production' to enable the preset's removal of console logs.
  • RETAIN_CONSOLE_LOGS: Set this to 'true' to retain console logs in a production build.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Ian Baker
Github

--- provides clear installation instructions, usage examples, and explains the preset's behavior, making it easy for others to use and understand.