utility.inlineEnvironmentVariables

How to use the utility.inlineEnvironmentVariables transformer.

Inlines environment variables.

Usage

require("babel").transform("code", { optional: ["utility.inlineEnvironmentVariables"] });
$ babel --optional utility.inlineEnvironmentVariables script.js

Example

For example compiling the following file:

script.js

if (process.env.NODE_ENV === "development") {
  development();
} else {
  production();
}

with the command:

$ NODE_ENV=development babel --optional utility.inlineEnvironmentVariables script.js

outputs:

if ("development" === "development") {
  development();
} else {
  production();
}

Use this in conjunction with the minification.deadCodeElimination transformer to output:

development();

Require hook

NOTE: When used in conjunction with the require hook, the require cache will not respond to changes in environment variables.