{"id":21383,"library":"git-revision-vite-plugin","title":"git-revision-vite-plugin","description":"A Vite plugin that injects git repository information (commit hash, version, branch, last commit datetime) as global constants at build time. Current stable version is 0.0.11, with experimental release cadence. Inspired by git-revision-webpack-plugin, it aims to provide equivalent functionality for Vite projects. Lightweight and zero-config by default, it exposes four globals: GIT_COMMITHASH, GIT_VERSION, GIT_BRANCH, GIT_LASTCOMMITDATETIME. Supports custom variable names, git commands, and lightweight tags. TypeScript types are included.","status":"active","version":"0.0.11","language":"javascript","source_language":"en","source_url":"https://github.com/a1067111756/git-revision-vite-plugin","tags":["javascript","vite","git","revision","plugin","typescript"],"install":[{"cmd":"npm install git-revision-vite-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add git-revision-vite-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add git-revision-vite-plugin","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export only; named import will fail.","wrong":"import { GitRevisionVitePlugin } from 'git-revision-vite-plugin'","symbol":"GitRevisionVitePlugin","correct":"import GitRevisionVitePlugin from 'git-revision-vite-plugin'"},{"note":"Globals are injected at build time via define, not environment variables.","wrong":"console.log(process.env.GIT_COMMITHASH)","symbol":"GIT_COMMITHASH","correct":"console.log(GIT_COMMITHASH)"},{"note":"Only visible if version option is true (default true).","wrong":"","symbol":"GIT_VERSION","correct":"console.log(GIT_VERSION)"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport vue from '@vitejs/plugin-vue';\nimport GitRevisionVitePlugin from 'git-revision-vite-plugin';\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    GitRevisionVitePlugin()\n  ]\n});\n\n// src/App.vue\n<script setup lang=\"ts\">\nconsole.log(GIT_COMMITHASH);\nconsole.log(GIT_VERSION);\nconsole.log(GIT_BRANCH);\nconsole.log(GIT_LASTCOMMITDATETIME);\n</script>\n\n<template>\n  <div>{{ GIT_COMMITHASH }}</div>\n</template>","lang":"typescript","description":"Shows plugin setup and usage of injected git globals in a Vue component."},"warnings":[{"fix":"Ensure you use these variables only in code that is processed by Vite (e.g., inside Vue SFCs or imported modules) and not in external scripts.","message":"Globals are only available at build time, not in runtime after build. They are replaced with string literals via Vite's define.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"If using lightweightTags, do not set versionCommand explicitly. Set version: false if not needed.","message":"The plugin's options for version, branch, commitHash default to true, but lightweightTags defaults to false. Setting lightweightTags: true is mutually exclusive with versionCommand and will throw an error if both are set.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Upgrade to 0.0.2 or later to use custom variable names.","message":"Option 'versionVar' and 'branchVar' defaults are outdated; variable names are hardcoded and cannot be fully customized in earlier versions.","severity":"deprecated","affected_versions":"<0.0.2"},{"fix":"Update any references to the old global names to the new ones: GIT_COMMITHASH, GIT_VERSION, GIT_BRANCH, GIT_LASTCOMMITDATETIME.","message":"In v0.0.2, default global variable names changed from all uppercase to GIT_COMMITHASH etc. Previously they might have been different strings.","severity":"breaking","affected_versions":"0.0.1"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Remove versionCommand when lightweightTags: true, or set lightweightTags: false.","cause":"Both options are mutually exclusive as lightweightTags implies custom git command for tags that conflicts with a custom versionCommand.","error":"Error: The option 'lightweightTags' cannot be used together with 'versionCommand'."},{"fix":"Only use these globals inside files processed by Vite (like .vue, .tsx, .js imported in src). They are compile-time constants.","cause":"The global is not available in Node.js runtime or after build in non-Vite processed files (e.g., in a plain .js file served statically).","error":"ReferenceError: GIT_COMMITHASH is not defined"},{"fix":"Use default import: import GitRevisionVitePlugin from 'git-revision-vite-plugin'.","cause":"Named import used instead of default import.","error":"TypeError: GitRevisionVitePlugin is not a constructor or function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}