{"id":22676,"library":"vite-plugin-git-commit-hash","title":"Vite Plugin Git Commit Hash","description":"A Vite plugin that injects the latest Git commit hash as a global `GIT_COMMIT_HASH` variable at build time. Current stable version is 1.0.7, released under MIT license. It is lightweight, has zero runtime dependencies (only peer dependency on Vite >=3), and ships TypeScript declarations. The plugin is ESM and CommonJS compatible. Key differentiator: it provides a simple, declarative way to expose git hash without complex build scripts or environment variables.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/Mocha--/vite-plugin-git-commit-hash","tags":["javascript","vite","git","commit-hash","typescript"],"install":[{"cmd":"npm install vite-plugin-git-commit-hash","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-git-commit-hash","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-git-commit-hash","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency to function as a Vite plugin.","package":"vite","optional":false}],"imports":[{"note":"This plugin exports a named function, not a default export.","wrong":"import gitCommitHashPlugin from 'vite-plugin-git-commit-hash'","symbol":"gitCommitHashPlugin","correct":"import { gitCommitHashPlugin } from 'vite-plugin-git-commit-hash'"},{"note":"GIT_COMMIT_HASH is a global variable defined at build time, not an imported symbol.","wrong":"import { GIT_COMMIT_HASH } from 'vite-plugin-git-commit-hash'","symbol":"GIT_COMMIT_HASH","correct":"console.log(GIT_COMMIT_HASH);  // global variable"},{"note":"The plugin does not export any types; you must declare the global in a declaration file.","wrong":"import type { GIT_COMMIT_HASH } from 'vite-plugin-git-commit-hash'","symbol":"type GIT_COMMIT_HASH","correct":"declare const GIT_COMMIT_HASH: string;  // in a .d.ts file"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { gitCommitHashPlugin } from 'vite-plugin-git-commit-hash';\n\nexport default defineConfig({\n  plugins: [gitCommitHashPlugin()],\n});\n\n// main.ts\nconsole.log(`App version: ${GIT_COMMIT_HASH}`);","lang":"typescript","description":"Shows how to add the plugin to Vite config and use the global GIT_COMMIT_HASH variable in your code."},"warnings":[{"fix":"Avoid using GIT_COMMIT_HASH as a variable name elsewhere, or use a different config option (if available).","message":"Plugin uses Vite's define() which replaces global identifiers literally. If your code uses a variable named GIT_COMMIT_HASH for another purpose, it will be overwritten.","severity":"breaking","affected_versions":"all"},{"fix":"Check process.env.NODE_ENV or use Vite's import.meta.env.DEV to conditionally access the hash.","message":"GIT_COMMIT_HASH is only available after build, not during development server (HMR) unless manually configured.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Vite to version 3 or higher.","message":"The plugin requires Vite >=3. Older Vite versions will cause errors.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add `declare const GIT_COMMIT_HASH: string;` to a .d.ts file (e.g., env.d.ts).","cause":"The global variable GIT_COMMIT_HASH is not recognized by TypeScript without a declaration.","error":"Cannot find name 'GIT_COMMIT_HASH'. Do you need to add a type declaration?"},{"fix":"Ensure the plugin is added to the Vite config's plugins array. In development, consider that GIT_COMMIT_HASH is replaced only after build.","cause":"The plugin may not be running or the variable is not replaced correctly in development mode.","error":"GIT_COMMIT_HASH is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}