How to use the utility.inlineEnvironmentVariables transformer.
Inlines environment variables.
require("babel").transform("code", { optional: ["utility.inlineEnvironmentVariables"] });
$ babel --optional utility.inlineEnvironmentVariables script.js
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();
NOTE: When used in conjunction with the require hook, the require cache will not respond to changes in environment variables.