Switch branches/tags
Find file History
boopathi Publish
 - babel-helper-evaluate-path@0.5.0
 - babel-helper-to-multiple-sequence-expressions@0.5.0
 - babel-minify@0.5.0
 - babel-plugin-minify-builtins@0.5.0
 - babel-plugin-minify-constant-folding@0.5.0
 - babel-plugin-minify-dead-code-elimination@0.5.0
 - babel-plugin-minify-mangle-names@0.5.0
 - babel-plugin-minify-replace@0.5.0
 - babel-plugin-minify-simplify@0.5.0
 - babel-plugin-transform-remove-undefined@0.5.0
 - babel-preset-minify@0.5.0
 - gulp-babel-minify@0.5.0
 - test-transform@0.0.4
Latest commit 4de3900 Sep 24, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
__tests__ chore: upgrade dependencies; fix tests Sep 24, 2018
src Upgrade deps (#522) May 5, 2017
.npmignore ignore *.log Jun 29, 2016
README.md add --save-dev to all packages' install instruction (#833) [skip ci] May 5, 2018
package.json Publish Sep 24, 2018

README.md

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