2.0.1 • Published 5 years ago

babel-plugin-transform-environment-variables-to-getters v2.0.1

Weekly downloads
31
License
MIT
Repository
github
Last release
5 years ago

Build Status Coverage

babel-plugin-transform-environment-variables-to-getters

The babel plugin to transform inline environment variables to value getters

Install

$ npm i babel-plugin-transform-environment-variables-to-getters

Example

In

console.log(process.env.NODE_ENV)
console.log(process.env.NODE_DEBUG)

Out

Via .babelrc with no options.exclude/include

{
  "plugins": [
    ["transform-environment-variables-to-getters", {
      "envFilepath": "/path/to/get-env.js"
    }]
  ]
}

Out

// We can change __PROCESS_ENVS_GETTER__ with `webpack.DefinePlugin`
const __getProcessEnvs = require('/path/to/get-env.js')

console.log(__getProcessEnvs().NODE_ENV)
console.log(__getProcessEnvs().NODE_DEBUG)

Via .babelrc with options

{
  "plugins": [
    ["transform-environment-variables-to-getters", {
      "envFilepath": "/path/to/get-env.js",
      "exclude": ["NODE_DEBUG"]
    }]
  ]
}

Out

const __getProcessEnvs = require('/path/to/get-env.js')

console.log(__getProcessEnvs().NODE_ENV)

// process.env.NODE_DEBUG is excluded
console.log(process.env.NODE_DEBUG)

options Object

  • envFilepath path the path of the environment file which should be a literal string
  • getterIdentifier? string='__getProcessEnvs' the identifier name of the env getter method
  • include? Array<string> keys to include. If not specified, all keys which are not excluded will be included
  • exclude? Array<string> keys to exclude.

License

MIT