babel-plugin-constif
This plugin allows Babel to remove remove if conditionals with string literals as condition.
Example
In
if ("IS_DEBUG")
console.log(1);
else
console.log(2);
Out
console.log(1);
console.log(2);
if ("IS_DEBUG")
console.log(1);
else
console.log(2);
Installation
npm install --save-dev babel-plugin-constif
Usage
Via .babelrc (Recommended)
.babelrc
{
"plugins": [
["constif", {var1: true, var2:false}]
]
}
Via CLI
VAR1=true babel --plugins constif script.js
Via Node API
require("babel-core").transform("code", {
plugins: [
["constif", {var1: true, var2:false}]
]
});