$ npm install babel-plugin-minify-replace
Configurable "search and replace" plugin. Replaces matching nodes in the tree with a given replacement node. For example you can replace process.NODE_ENV
with "production"
.
Options
[
{
identifierName: "__DEV__",
replacement: {
type: "numericLiteral",
value: 0,
},
},
]
In
if (!__DEV__) {
foo();
}
if (a.__DEV__) {
foo();
}
Out
if (!0) {
foo();
}
if (a.__DEV__) {
foo();
}
npm install babel-plugin-minify-replace
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["minify-replace"]
}
// with options
{
"plugins": [
["minify-replace", {
"replacements": [{
"identifierName": "__DEV__",
"replacement": {
"type": "booleanLiteral",
"value": true
}
}]
}]
]
}
babel --plugins minify-replace script.js
require("@babel/core").transform("code", {
plugins: ["minify-replace"]
});
© 2010 - cnpmjs.org x YWFE | Home | YWFE