1. 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"`.
babel-plugin-minify-replace
Package: babel-plugin-minify-replace
Created by: babel
Last modified: Fri, 21 Jul 2023 15:40:54 GMT
Version: 0.5.0
License: MIT
Downloads: 1,776,502
Repository: https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-replace

Install

npm install babel-plugin-minify-replace
yarn add babel-plugin-minify-replace

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

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code