The babel plugin to transform inline environment variables to value getters
$ npm i babel-plugin-transform-environment-variables-to-getters
console.log(process.env.NODE_ENV)
console.log(process.env.NODE_DEBUG)
{
"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)
{
"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)
- 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.