NODE_ENV inline transform

Inline the NODE_ENV environment variable and if it's a part of a binary expression

示例

输入

process.env.NODE_ENV === "development";
process.env.NODE_ENV === "production";

输出

NODE_ENV=development babel in.js --plugins transform-node-env-inline
true;
false;

安装

npm install babel-plugin-transform-node-env-inline

用法

通过 .babelrc(推荐)

.babelrc

{
  "plugins": ["transform-node-env-inline"]
}

通过 CLI

babel --plugins transform-node-env-inline script.js

通过 Node API

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