{"id":20635735,"url":"https://github.com/zhongxuyang/vite-plugin-version-mark","last_synced_at":"2025-04-04T20:03:17.683Z","repository":{"id":61809499,"uuid":"555317741","full_name":"ZhongxuYang/vite-plugin-version-mark","owner":"ZhongxuYang","description":"Automatically use `package version` / `git commit` / `custom` to be inserted into your project as a unique identifier for the project version.","archived":false,"fork":false,"pushed_at":"2024-12-05T05:08:27.000Z","size":5162,"stargazers_count":61,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-19T09:21:07.031Z","etag":null,"topics":["nuxt-modules","vite-plugin"],"latest_commit_sha":null,"homepage":"https://zhongxuyang.github.io/vite-plugin-version-mark/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZhongxuYang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-21T10:47:30.000Z","updated_at":"2025-01-14T22:54:53.000Z","dependencies_parsed_at":"2024-01-07T18:05:07.591Z","dependency_job_id":"7b7bd9c7-226d-4866-8308-c60a5eb6929c","html_url":"https://github.com/ZhongxuYang/vite-plugin-version-mark","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"343ce2cd2e118541ceba66371a7b9031b19145e2"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhongxuYang%2Fvite-plugin-version-mark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhongxuYang%2Fvite-plugin-version-mark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhongxuYang%2Fvite-plugin-version-mark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZhongxuYang%2Fvite-plugin-version-mark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZhongxuYang","download_url":"https://codeload.github.com/ZhongxuYang/vite-plugin-version-mark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246085596,"owners_count":20721210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nuxt-modules","vite-plugin"],"created_at":"2024-11-16T15:06:59.621Z","updated_at":"2025-03-28T19:02:34.198Z","avatar_url":"https://github.com/ZhongxuYang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv style=\"text-align: right;\"\u003e\n\n[中文](./README_ZH.md) | English\n\n\u003c/div\u003e\n\n# vite-plugin-version-mark\n\n\u003e Automatically insert the version or git_commit_sha in your Vite/Nuxt project.\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ZhongxuYang/vite-plugin-version-mark/tree/main\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ZhongxuYang/images/dev/common/version.svg\" width=\"300px\" height=\"100px\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![types][types-src]][types-href]\n[![License][license-src]][license-href]\n\n[![Vite][vite-src]][vite-href]\n[![Nuxt][nuxt-src]][nuxt-href]\n\n[![Awesome][awesome-src]][awesome-href]\n\n\u003c/div\u003e\n\n## Example\n\n[![](https://raw.githubusercontent.com/ZhongxuYang/images/dev/common/version-shot.png)](https://zhongxuyang.github.io/vite-plugin-version-mark)\n\n## Install\n```sh\npnpm add -D vite-plugin-version-mark\n# OR yarn add -D vite-plugin-version-mark\n# OR npm install -D vite-plugin-version-mark\n```\n\n## Usage\n### Vite\n```ts\n// vite.config.ts\nimport {defineConfig} from 'vite'\nimport {vitePluginVersionMark} from 'vite-plugin-version-mark'\n\nexport default defineConfig({\n  plugins: [\n    vitePluginVersionMark({\n      // name: 'test-app',\n      // version: '0.0.1',\n      // command: 'git describe --tags',\n      // outputFile: true,\n      // ifGitSHA: true,\n      ifShortSHA: true,\n      ifMeta: true,\n      ifLog: true,\n      ifGlobal: true,\n    })\n  ],\n})\n```\n\n### Nuxt3+\n```ts\n// nuxt.config.ts\nexport default defineNuxtConfig({\n  modules: [\n    ['vite-plugin-version-mark/nuxt', {\n      // name: 'test-app',\n      // version: '0.0.1',\n      // command: 'git describe --tags',\n      // outputFile: true,\n      // ifGitSHA: true, \n      ifShortSHA: true, \n      ifMeta: true, \n      ifLog: true, \n      ifGlobal: true,\n    }]\n  ],\n})\n```\n\nThen you can use `vite-plugin-version-mark` ! 🎉\n\n## Config\n\n\u003e `vite-plugin-version-mark` can be print application version in the `Console`, defined `global` or add `\u003cmeta\u003e` in HTML element. \n\n| Name | Description | Type | Default | Supported |\n| --- | --- | --- | --- | --- |\n| name | application name | `string` | `name` in package.json | `0.0.1+` |\n| version | application version | `string` | `version` in package.json | `0.0.1+` |\n| ifGitSHA | use git commit SHA as the version | `boolean` | false | `0.0.1+` |\n| ifShortSHA | use git commit short SHA as the version | `boolean` | false | `0.0.1+` |\n| command | provide a custom command to retrieve the version \u003cbr/\u003eFor example: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` |\n| ifLog | print info in the Console | `boolean` | true | `0.0.1+` |\n| ifGlobal | set a variable named *\\`\\_\\_${APPNAME}\\_VERSION\\_\\_\\`* in the window\u003cbr/\u003e[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+` |\n| ifMeta | add \\\u003cmeta name=\"application-name\" content=\"{APPNAME_VERSION}: {version}\"\u003e in the \\\u003chead\u003e | `boolean` | true | `0.0.1+` |\n| ifExport | export the version field in the entry file. This may be used when you use vite to build a `library mode`.\u003cbr/\u003eThrough `import { {APPNAME}_VERSION } from \u003cyour_library_name\u003e` | `boolean` | false | `0.0.11+` |\n| outputFile | The build generates a static file based on the version, as described in the `outputFile` configuration below. | `boolean`/`function` | false | `0.1.1+` |\n\n\u003e The **version field** takes precedence: `command` \u003e `ifShortSHA`  \u003e `ifGitSHA` \u003e `version`\n\n### `outputFile` Configuration Option\n\nIf you want to enable it, you can set it to `true`, and it will create a file with the path `.well-known/version` and the content of the current version number in the relative build directory (*dist* for `vite` and *.output/public* for `nuxt3`).\n\nAlternatively, it can be set to a function that takes the version number as a parameter and returns an object. This allows you to define the content information generated, for example:\n\n```ts\n// vite.config.ts\nvitePluginVersionMark({\n  // ...other options\n\n  outputFile: (version) =\u003e ({\n    path: 'custom/version.json',\n    content: `{\"version\":\"${version}\"}`,\n  })\n}),\n```\n\nWith this configuration, a file named `custom/version.json` will be generated, and its content will be `{\"version\":\"${current version number}\"}`.\n\n## Other\n\n### How to get the version in your vitePlugin?\n```ts\n// vite.config.ts\n\nimport {defineConfig} from 'vite'\nimport type {Plugin} from 'vite'\nimport {vitePluginVersionMark} from 'vite-plugin-version-mark'\n\nconst yourPlugin: () =\u003e Plugin = () =\u003e ({\n  name: 'test-plugin',\n  config (config) {\n    // get version in vitePlugin if you open `ifGlobal`\n    console.log(config.define)\n  }\n})\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    vitePluginVersionMark({\n      ifGlobal: true,\n    }),\n    yourPlugin(),\n  ],\n})\n\n```\n\n### How to get the branch to which it belongs through `commit SHA`?\n\nThrough the `git` command below, you can list all branches containing the specified `commit SHA`.\n\n```sh\ngit branch -r --contains \u003cCOMMIT_SHA\u003e\n```\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=ZhongxuYang/vite-plugin-version-mark\u0026type=Date)](https://star-history.com/#ZhongxuYang/vite-plugin-version-mark\u0026Date)\n\n\nView [CHANGELOG](./CHANGELOG.md)\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/vite-plugin-version-mark/latest.svg?style=flat\u0026colorA=18181B\n[npm-version-href]: https://www.npmjs.com/package/vite-plugin-version-mark?activeTab=versions\n\n[npm-downloads-src]: https://img.shields.io/npm/dm/vite-plugin-version-mark.svg?style=flat\u0026colorA=18181B\n[npm-downloads-href]: https://npmcharts.com/compare/vite-plugin-version-mark?interval=7\u0026minimal=true\n\n[types-src]: https://img.shields.io/npm/types/vite-plugin-version-mark.svg?style=flat\u0026colorA=18181B\n[types-href]: https://npmjs.com/package/vite-plugin-version-mark\n\n[license-src]: https://img.shields.io/npm/l/vite-plugin-version-mark.svg?style=flat\u0026colorA=18181B\n[license-href]: https://npmjs.com/package/vite-plugin-version-mark\n\n[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?\u0026logo=nuxt.js\n[nuxt-href]: https://nuxt.com\n\n[vite-src]: https://img.shields.io/badge/Vite-18181B?\u0026logo=vite\n[vite-href]: https://vitejs.dev\n\n[awesome-src]: https://awesome.re/mentioned-badge.svg\n[awesome-href]: https://github.com/vitejs/awesome-vite#transformers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongxuyang%2Fvite-plugin-version-mark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhongxuyang%2Fvite-plugin-version-mark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhongxuyang%2Fvite-plugin-version-mark/lists"}