Naturally Produced Modules

    rollup-plugin-baked-env

    1.0.0 • Public • Published

    rollup-plugin-baked-env

    LICENSE Node CodeFactor

    Coverage Status Travis

    Version Downloads

    This plugin allow you to use environment variables inside your code by importing process.env as a faux module. The environment variable will be baked in your code at compile time. Only the variables being used are included.

    Installation

    NPM

    npm install --save-dev rollup-plugin-baked-env
    

    Yarn

    yarn add --dev rollup-plugin-baked-env
    

    Adding to your project

    rollup.config.js

    import bakedEnv from 'rollup-plugin-baked-env';
    
    export default {
        // ...
        plugins: [
            bakedEnv(),
        ],
    };

    Usage Examples

    Inside your code you can do something like this:

    Basic usage

    import { NODE_ENV } from 'process.env';
    
    if (NODE_ENV === 'production') {
        // code
    }

    Import variable, aliasing it to another name

    import { ROLLUP_WATCH as isDev } from 'process.env';
    
    if (isDev) {
        // code
    }
    else {
        // code
    }

    Import multiple variables

    import { NODE_ENV, FOO, BAR } from 'process.env';
    
    console.log(FOO, BAR);
    if (NODE_ENV === 'production') {
        // code
    }

    Import all variables

    import * as env from 'process.env'; // ✋ use with caution!
    
    if (env.production !== 'production') {
        console.log('My home directory is ' + env.HOME);
    }

    NOTE: If you do import * as env from 'process.env' never use the env variable directly! This will cause rollup to embed ALL environment variables inside your bundle.

    import * as env from 'process.env';
    
    // DON'T DO THIS!
    console.log(env); // BAD!
    
    Object.keys(env).filter(/* ... */) // BAD! (if you access the env at runtime, it will force rollup to embed everything)

    Validation by default

    Your code will fail to compile if the code imports variables that are not set!

    image

    image

    Options

    License

    The code is available under the MIT license.

    Contributing

    We are open to contributions, see CONTRIBUTING.md for more info.

    Install

    npm i rollup-plugin-baked-env

    DownloadsWeekly Downloads

    61

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    304 kB

    Total Files

    10

    Last publish

    Collaborators

    • vitim