Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ZhongxuYang/vite-plugin-version-mark
Automatically use `package version` / `git commit` / `custom` to be inserted into your project as a unique identifier for the project version.
https://github.com/ZhongxuYang/vite-plugin-version-mark
nuxt-modules vite-plugin
Last synced: 3 months ago
JSON representation
Automatically use `package version` / `git commit` / `custom` to be inserted into your project as a unique identifier for the project version.
- Host: GitHub
- URL: https://github.com/ZhongxuYang/vite-plugin-version-mark
- Owner: ZhongxuYang
- Created: 2022-10-21T10:47:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T03:28:23.000Z (3 months ago)
- Last Synced: 2024-10-22T21:52:19.338Z (3 months ago)
- Topics: nuxt-modules, vite-plugin
- Language: TypeScript
- Homepage: https://zhongxuyang.github.io/vite-plugin-version-mark/
- Size: 3.31 MB
- Stars: 53
- Watchers: 4
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- fucking-awesome-vite - vite-plugin-version-mark - Automatically use `package version` / `git commit` / `custom` to be inserted into your project as a unique identifier for the project version. (Plugins / Framework-agnostic Plugins)
- awesome-vite - vite-plugin-version-mark - Automatically use `package version` / `git commit` / `custom` to be inserted into your project as a unique identifier for the project version. (Plugins / Framework-agnostic Plugins)
README
[δΈζ](./README_ZH.md) | English
# vite-plugin-version-mark
> Automatically insert the version or git_commit_sha in your Vite/Nuxt project.
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![types][types-src]][types-href]
[![License][license-src]][license-href][![Vite][vite-src]][vite-href]
[![Nuxt][nuxt-src]][nuxt-href][![Awesome][awesome-src]][awesome-href]
## Demo
![](https://raw.githubusercontent.com/ZhongxuYang/images/dev/common/version-shot.png)## Install
```sh
pnpm add -D vite-plugin-version-mark
# OR yarn add -D vite-plugin-version-mark
# OR npm install -D vite-plugin-version-mark
```## Usage
### Vite
```ts
// vite.config.ts
import {defineConfig} from 'vite'
import {vitePluginVersionMark} from 'vite-plugin-version-mark'export default defineConfig({
plugins: [
vitePluginVersionMark({
// name: 'test-app',
// version: '0.0.1',
// command: 'git describe --tags',
// ifGitSHA: true,
ifShortSHA: true,
ifMeta: true,
ifLog: true,
ifGlobal: true,
})
],
})
```### Nuxt3+
```ts
// nuxt.config.ts
export default defineNuxtConfig({
modules: [
['vite-plugin-version-mark/nuxt', {
// name: 'test-app',
// version: '0.0.1',
// command: 'git describe --tags',
// ifGitSHA: true,
ifShortSHA: true,
ifMeta: true,
ifLog: true,
ifGlobal: true,
}]
],
})
```Then you can use `vite-plugin-version-mark` ! π
## Config
> `vite-plugin-version-mark` can be print application version in the `Console`, defined `global` or add `` in HTML element.
| Name | Description | Type | Default | Supported |
| --- | --- | --- | --- | --- |
| name | application name | `string` | `name` in package.json | `0.0.1+` |
| version | application version | `string` | `version` in package.json | `0.0.1+` |
| ifGitSHA | use git commit SHA as the version | `boolean` | false | `0.0.1+` |
| ifShortSHA | use git commit short SHA as the version | `boolean` | false | `0.0.1+` |
| command | provide a custom command to retrieve the version
For example: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |
| ifLog | print info in the Console | `boolean` | true | `0.0.1+` |
| ifGlobal | set a variable named *\`\_\_${APPNAME}\_VERSION\_\_\`* in the window
[For TypeScript users, make sure to add the type declarations in the env.d.ts or vite-env.d.ts file to get type checks and Intellisense.](https://vitejs.dev/config/shared-options.html#define) | `boolean` | true | `0.0.4+` |
| ifMeta | add \ in the \ | `boolean` | true | `0.0.1+` |
| ifExport | export the version field in the entry file. This may be used when you use vite to build a `library mode`.
Through `import { {APPNAME}_VERSION } from ` | `boolean` | false | `0.0.11+` |> The **version field** takes precedence: `command` > `ifShortSHA` > `ifGitSHA` > `version`
## Other
### How to get the version in your vitePlugin?
```ts
// vite.config.tsimport {defineConfig} from 'vite'
import type {Plugin} from 'vite'
import {vitePluginVersionMark} from 'vite-plugin-version-mark'const yourPlugin: () => Plugin = () => ({
name: 'test-plugin',
config (config) {
// get version in vitePlugin if you open `ifGlobal`
console.log(config.define)
}
})export default defineConfig({
plugins: [
vue(),
vitePluginVersionMark({
ifGlobal: true,
}),
yourPlugin(),
],
})```
### How to get the branch to which it belongs through `commit SHA`?
Through the `git` command below, you can list all branches containing the specified `commit SHA`.
```sh
git branch -r --contains
```View [CHANGELOG](./CHANGELOG.md)
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=ZhongxuYang/vite-plugin-version-mark&type=Date)](https://star-history.com/#ZhongxuYang/vite-plugin-version-mark&Date)
[npm-version-src]: https://img.shields.io/npm/v/vite-plugin-version-mark/latest.svg?style=flat&colorA=18181B
[npm-version-href]: https://npmjs.com/package/vite-plugin-version-mark[npm-downloads-src]: https://img.shields.io/npm/dm/vite-plugin-version-mark.svg?style=flat&colorA=18181B
[npm-downloads-href]: https://npmjs.com/package/vite-plugin-version-mark[types-src]: https://img.shields.io/npm/types/vite-plugin-version-mark.svg?style=flat&colorA=18181B
[types-href]: https://npmjs.com/package/vite-plugin-version-mark[license-src]: https://img.shields.io/npm/l/vite-plugin-version-mark.svg?style=flat&colorA=18181B
[license-href]: https://npmjs.com/package/vite-plugin-version-mark[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?&logo=nuxt.js
[nuxt-href]: https://nuxt.com[vite-src]: https://img.shields.io/badge/Vite-18181B?&logo=vite
[vite-href]: https://vitejs.dev[awesome-src]: https://awesome.re/mentioned-badge.svg
[awesome-href]: https://github.com/vitejs/awesome-vite#transformers