babel-plugin-minify-replace
Example
Options
JavaScript
[
{
identifierName: "__DEV__",
replacement: {
type: "numericLiteral",
value: 0,
},
},
]
In
JavaScript
if (!__DEV__) {
foo();
}
if (a.__DEV__) {
foo();
}
Out
JavaScript
if (!0) {
foo();
}
if (a.__DEV__) {
foo();
}
Installation
- npm
- Yarn
- pnpm
npm install babel-plugin-minify-replace --save-dev
yarn add babel-plugin-minify-replace --dev
pnpm add babel-plugin-minify-replace --save-dev
Usage
With a configuration file (Recommended)
JSON
// without options
{
"plugins": ["minify-replace"]
}
JSON
// with options
{
"plugins": [
["minify-replace", {
"replacements": [{
"identifierName": "__DEV__",
"replacement": {
"type": "booleanLiteral",
"value": true
}
}]
}]
]
}
Via CLI
Shell
babel --plugins minify-replace script.js
Via Node API
JavaScript
require("@babel/core").transformSync("code", {
plugins: ["minify-replace"]
});