Skip to content

Load your .env file and replace 'process.env.MY_VARIABLE' with the value you set.

Notifications You must be signed in to change notification settings

brysgo/babel-plugin-inline-dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-inline-dotenv

Test

npm package

Load your .env file and replace process.env.MY_VARIABLE with the value you set.

tl;dr

It actually replaces process.env.MY_VARIABLE with:

process && process.env && process.env.MY_VARIABLE || 'value assigned to variable in dotenv'

This way, if the value is available at runtime it will be used instead.

Installation

$ npm install babel-plugin-inline-dotenv

Usage

Via .babelrc (Recommended)

Without options:

.babelrc

{
  "plugins": ["inline-dotenv"]
}

With options:

{
  "plugins": [["inline-dotenv",{
    path: 'path/to/.env' // See motdotla/dotenv for more options
  }]]
}

To replace with env value without process && process.env && process.env.MY_VARIABLE || safety:

{
  "plugins": [["inline-dotenv",{
    unsafe: true
  }]]
}

The plugin support 3 mode to read the env var from the system :

{
  "plugins": [["inline-dotenv",{
    systemVar: 'all' | 'overwrite' | 'disable'
  }]]
}
  • all default, every env var found in process.env will be used

    ⚠️ This could leak super secret stuffs !

  • overwrite, the value in process.env will overwrite the one present in .env only. Your .env file act as a whitelist

  • disable, the process.env will not be used at all

Via CLI

$ babel --plugins inline-dotenv script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["inline-dotenv"]
});

About

Load your .env file and replace 'process.env.MY_VARIABLE' with the value you set.

Resources

Stars

Watchers

Forks

Packages

No packages published