Skip to content

Latest commit

 

History

History
93 lines (75 loc) · 1.07 KB

plugin-minify-replace.md

File metadata and controls

93 lines (75 loc) · 1.07 KB
id title sidebar_label original_id
version-6.26.3-babel-plugin-minify-replace
babel-plugin-minify-replace
minify-replace
babel-plugin-minify-replace

Example

Options

[
  {
    identifierName: "__DEV__",
    replacement: {
      type: "numericLiteral",
      value: 0,
    },
  },
]

In

if (!__DEV__) {
  foo();
}
if (a.__DEV__) {
  foo();
}

Out

if (!0) {
  foo();
}
if (a.__DEV__) {
  foo();
}

Installation

npm install babel-plugin-minify-replace

Usage

With a configuration file (Recommended)

// without options
{
  "plugins": ["minify-replace"]
}
// with options
{
  "plugins": [
    ["minify-replace", {
      "replacements": [{
        "identifierName": "__DEV__",
        "replacement": {
          "type": "booleanLiteral",
          "value": true
        }
      }]
    }]
  ]
}

Via CLI

babel --plugins minify-replace script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["minify-replace"]
});