babel-plugin-constif
v1.1.0
Published
This plugin allows Babel to remove if conditionals with string literals as condition.
Downloads
4
Readme
babel-plugin-constif
This plugin allows Babel to remove if conditionals with string literals as condition.
Example
In
if ("isDebug")
console.log(1);
else
console.log(2);
Out
// IS_DEBUG=true babel script.js
console.log(1);
// IS_DEBUG=false babel script.js
console.log(2);
// babel script.js
if ("isDebug")
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 VAR2=0 babel --plugins constif script.js
Via Node API
require("babel-core").transform("code", {
plugins: [
["constif", {var1: true, var2:false}]
]
});