babel-plugin-minify-replace

Example

Options

  1. [
  2. {
  3. identifierName: "__DEV__",
  4. replacement: {
  5. type: "numericLiteral",
  6. value: 0,
  7. },
  8. },
  9. ]

In

  1. if (!__DEV__) {
  2. foo();
  3. }
  4. if (a.__DEV__) {
  5. foo();
  6. }

Out

  1. if (!0) {
  2. foo();
  3. }
  4. if (a.__DEV__) {
  5. foo();
  6. }

Installation

  1. npm install babel-plugin-minify-replace --save-dev

Usage

.babelrc

  1. // without options
  2. {
  3. "plugins": ["minify-replace"]
  4. }
  1. // with options
  2. {
  3. "plugins": [
  4. ["minify-replace", {
  5. "replacements": [{
  6. "identifierName": "__DEV__",
  7. "replacement": {
  8. "type": "booleanLiteral",
  9. "value": true
  10. }
  11. }]
  12. }]
  13. ]
  14. }

Via CLI

  1. babel --plugins minify-replace script.js

Via Node API

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