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"`.

MIT 83 个版本
安装
npm install babel-plugin-minify-replace
yarn add babel-plugin-minify-replace
pnpm add babel-plugin-minify-replace
bun add babel-plugin-minify-replace
README

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".

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 --save-dev

Usage

.babelrc

// 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"]
});
版本列表
0.5.0-alpha.9 2018-09-23
0.5.0 2018-09-24
0.4.3 2018-05-14
0.4.2 2018-05-14
0.4.1 2018-05-03
0.4.0 2018-04-08
0.3.0 2018-01-31
0.2.0 2017-08-14
0.1.2 2017-06-13
0.1.1 2017-05-22
0.1.0 2017-05-22
0.0.4 2017-03-03
0.0.3 2017-02-08
0.0.2 2017-01-17
0.0.1 2016-08-26