Negotiate Pushing Milestone

    babel-plugin-env-constants
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    babel-plugin-env-constants

    Build Status npm version

    Transform __DEV__, __PROD__, and __TEST__ constants to process.env.NODE_ENV conditionals.

    // Input
    if (__DEV__) {
    	console.log('Some message in development!');
    }
    
    const value = __TEST__ ? 0 : 100;
    // Output
    if (process.env.NODE_ENV !== 'production') {
    	console.log('Some message in development!');
    }
    
    const value = process.env.NODE_ENV === 'test' ? 0 : 100;

    Installation

    yarn add --dev babel-plugin-env-constants
    

    Add the plugin to your root babel.config.* file.

    module.exports = {
    	plugins: ['babel-plugin-env-constants'],
    };

    And if you are using TypeScript, you'll most likely need to declare the globals yourself.

    declare global {
    	const __DEV__: boolean;
    	const __PROD__: boolean;
    	const __TEST__: boolean;
    }

    Requirements

    • Linux, OSX, Windows
    • Node 12.17+

    Install

    npm i babel-plugin-env-constants

    DownloadsWeekly Downloads

    65

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    8.17 kB

    Total Files

    11

    Last publish

    Collaborators

    • milesj