Skip to main content

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 install babel-plugin-minify-replace --save-dev

Usage

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"]
});