Adapted from https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-node-env-inline
babel-plugin-transform-babel-env-inline
Inline the BABEL_ENV
environment variable and if it's a part of a binary expression
(eg. process.env.BABEL_ENV === "react"
) then statically evaluate and replace it.
Example
In
process.env.BABEL_ENV === "react";
process.env.BABEL_ENV === "inferno";
Out
BABEL_ENV=react babel in.js --plugins transform-babel-env-inline
true;
false;
Installation
npm install babel-plugin-transform-babel-env-inline
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["transform-babel-env-inline"]
}
Via CLI
babel --plugins transform-babel-env-inline script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["transform-babel-env-inline"]
});