Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hustcc/babel-plugin-version
:label: babel plugin replace define identifier `__VERSION__` to pkg.version!
https://github.com/hustcc/babel-plugin-version
babel babel-plugin version
Last synced: 2 months ago
JSON representation
:label: babel plugin replace define identifier `__VERSION__` to pkg.version!
- Host: GitHub
- URL: https://github.com/hustcc/babel-plugin-version
- Owner: hustcc
- Created: 2018-11-16T01:36:11.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-19T03:14:51.000Z (almost 6 years ago)
- Last Synced: 2024-10-17T16:04:39.549Z (3 months ago)
- Topics: babel, babel-plugin, version
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-babel - version - Babel plugin replace defined identifier `__VERSION__` to pkg.version. (Plugins / General Plugins)
README
# babel-plugin-version
A babel plugin replace define Identifier / StringLiteral to pkg.version!
[![npm](https://img.shields.io/npm/v/babel-plugin-version.svg)](https://www.npmjs.com/package/babel-plugin-version)
[![npm](https://img.shields.io/npm/dm/babel-plugin-version.svg)](https://www.npmjs.com/package/babel-plugin-version)## Install
> npm i --save-dev babel-plugin-version
## Usage
Add it into `.babelrc`.
```json
{
"plugins": [
"version"
]
}
```## Result
- Input
```js
const a = { a: __VERSION__ };const b = a === __VERSION__;
const c = [__VERSION__];
const d =__VERSION__ = 1;
const e = "__VERSION__";
```- Output
```js
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.
```json
{
"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 inpm t
```Then see the files in `lib` dir.
## License
MIT