A babel plugin replace define Identifier / StringLiteral to pkg.version!
npm i --save-dev babel-plugin-version
Add it into .babelrc
.
{
"plugins": [
"version"
]
}
- 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";
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
. Defaulttrue
. Whether transform identifier which's name is equaldefine
string. - stringLiteral,
boolean
. Defaulttrue
. Whether transform string variable which is equaldefine
string.
npm i
npm t
Then see the files in lib
dir.
MIT