Skip to content

🏷️ babel plugin replace define identifier `__VERSION__` to pkg.version!

Notifications You must be signed in to change notification settings

hustcc/babel-plugin-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 
     }]
  ]
}
  • define, string. Default __VERSION__. Define the keyword string which will be transformed.
  • identifier, boolean. Default true. Whether transform identifier which's name is equal define string.
  • stringLiteral, boolean. Default true. Whether transform string variable which is equal define string.

Test

npm i

npm t

Then see the files in lib dir.

License

MIT

About

🏷️ babel plugin replace define identifier `__VERSION__` to pkg.version!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published