babel-plugin-minify-replace

0.5.0 • Public • Published

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

Via .babelrc (Recommended)

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

Dependents (46)

Package Sidebar

Install

npm i babel-plugin-minify-replace

Weekly Downloads

398,536

Version

0.5.0

License

MIT

Unpacked Size

5.12 kB

Total Files

4

Last publish

Collaborators

  • nicolo-ribaudo
  • boopathi
  • hzoo
  • vignesh.shanmugam
  • loganfsmyth