babel-plugin-transform-inline-environment-variables
Example
In
JavaScript
// assuming process.env.NODE_ENV is actually "development"
process.env.NODE_ENV;
Out
JavaScript
"development";
Installation
- npm
- Yarn
- pnpm
npm install babel-plugin-transform-inline-environment-variables --save-dev
yarn add babel-plugin-transform-inline-environment-variables --dev
pnpm add babel-plugin-transform-inline-environment-variables --save-dev
Usage
With a configuration file (Recommended)
JSON
// without options
{
"plugins": ["transform-inline-environment-variables"]
}
// with options
{
"plugins": [
["transform-inline-environment-variables", {
"include": [
"NODE_ENV"
]
}]
]
}
Via CLI
Shell
babel --plugins transform-inline-environment-variables script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["transform-inline-environment-variables"],
});
Options
include
- array of environment variables to includeexclude
- array of environment variables to exclude
tip
You can read more about configuring plugin options here