Replace member expressions and typeof statements with strings and statically evaluate them if possible, like webpack's DefinePlugin
for Babel.
// assuming options are { "process.env.NODE_ENV": "development", "typeof window": "object" }
process.env.NODE_ENV;
process.env.NODE_ENV === "development";
typeof window;
typeof window === "object";
'development';
true;
'object';
true;
$ npm install babel-plugin-transform-define
.babelrc
{
"plugins": ["transform-define", {
"process.env.NODE_ENV": "production",
"typeof window": "object"
}]
}
$ babel --plugins transform-define script.js
require("babel-core").transform("code", {
plugins: ["transform-define", {
"process.env.NODE_ENV": "production",
"typeof window": "object"
}]
});