1. babel-plugin-version
babel plugin replace define Identifier / StringLiteral `__VERSION__` to pkg.version!
babel-plugin-version
Package: babel-plugin-version
Last modified: Mon, 11 Apr 2022 16:46:19 GMT
Version: 0.2.3
License: MIT
Downloads: 583

Install

npm install babel-plugin-version
yarn add babel-plugin-version

babel-plugin-version

A babel plugin replace define Identifier / StringLiteral to pkg.version!

npm
npm

Install

npm i --save-dev babel-plugin-version

Usage

Add it into .babelrc.

 {
  "plugins": [
    "version"
  ]
}

Result

  • Input
 const a = { a: __VERSION__ };

const b = a === __VERSION__;

const c = [__VERSION__];

const d =__VERSION__ = 1;

const e = "__VERSION__";
  • Output
 const a = { a: "0.1.0" };

const b = a === "0.1.0";

const c = ["0.1.0"];

const d = __VERSION__ = 1;

const e = "0.1.0";

Configure

You can customize the default __VERSION__ define.

 {
  "plugins": [
    ["version", {
      "define": "__PKG_VERSION__",
      "identifier": false,
      "stringLiteral": true 
     }]
  ]
}

Test

npm i

npm t

Then see the files in lib dir.

License

MIT

Dependencies

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