Registry / devops / git-revision-vite-plugin

git-revision-vite-plugin

JSON →
library0.0.11jsnpmunverified

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.

npm install git-revision-vite-plugin
INSTALL
IMPORT
SIG · GIT-REVISION-VITE-
G
git-revision-vite-plugin
devopsjavascriptv0.0.11
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GitRevisionVitePlugin
import GitRevisionVitePlugin from 'git-revision-vite-plugin'
import { GitRevisionVitePlugin } from 'git-revision-vite-plugin'
Default export only; named import will fail.
GIT_COMMITHASH
console.log(GIT_COMMITHASH)
console.log(process.env.GIT_COMMITHASH)
Globals are injected at build time via define, not environment variables.
GIT_VERSION
console.log(GIT_VERSION)
Only visible if version option is true (default true).

Shows plugin setup and usage of injected git globals in a Vue component.

// vite.config.js import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import GitRevisionVitePlugin from 'git-revision-vite-plugin'; export default defineConfig({ plugins: [ vue(), GitRevisionVitePlugin() ] }); // src/App.vue <script setup lang="ts"> console.log(GIT_COMMITHASH); console.log(GIT_VERSION); console.log(GIT_BRANCH); console.log(GIT_LASTCOMMITDATETIME); </script> <template> <div>{{ GIT_COMMITHASH }}</div> </template>
Debug
Known issues
gotchaGlobals are only available at build time, not in runtime after build. They are replaced with string literals via Vite's define.
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.
affects: >=0.0.1
gotchaThe 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.
fix
If using lightweightTags, do not set versionCommand explicitly. Set version: false if not needed.
affects: >=0.0.1
deprecatedOption 'versionVar' and 'branchVar' defaults are outdated; variable names are hardcoded and cannot be fully customized in earlier versions.
fix
Upgrade to 0.0.2 or later to use custom variable names.
affects: <0.0.2
breakingIn v0.0.2, default global variable names changed from all uppercase to GIT_COMMITHASH etc. Previously they might have been different strings.
fix
Update any references to the old global names to the new ones: GIT_COMMITHASH, GIT_VERSION, GIT_BRANCH, GIT_LASTCOMMITDATETIME.
affects: 0.0.1
Errors
Common errors & fixes
Error: The option 'lightweightTags' cannot be used together with 'versionCommand'.
Both options are mutually exclusive as lightweightTags implies custom git command for tags that conflicts with a custom versionCommand.
fix
Remove versionCommand when lightweightTags: true, or set lightweightTags: false.
ReferenceError: GIT_COMMITHASH is not defined
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).
fix
Only use these globals inside files processed by Vite (like .vue, .tsx, .js imported in src). They are compile-time constants.
TypeError: GitRevisionVitePlugin is not a constructor or function
Named import used instead of default import.
fix
Use default import: import GitRevisionVitePlugin from 'git-revision-vite-plugin'.
Upgrade
Version history
0.0.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
git-revision-vite-plugin — npm install git-revision-vite-plugin · libregistry