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.

devops
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.

Default export only; named import will fail.

import GitRevisionVitePlugin from 'git-revision-vite-plugin'

Globals are injected at build time via define, not environment variables.

console.log(GIT_COMMITHASH)

Only visible if version option is true (default true).

console.log(GIT_VERSION)

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 footguns
gotchaGlobals are only available at build time, not in runtime after build. They are replaced with string literals via Vite's define.
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.
deprecatedOption 'versionVar' and 'branchVar' defaults are outdated; variable names are hardcoded and cannot be fully customized in earlier versions.
breakingIn v0.0.2, default global variable names changed from all uppercase to GIT_COMMITHASH etc. Previously they might have been different strings.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
13 hits · last 30 days
gptbot
4
ahrefsbot
4
claudebot
3
script
1
bingbot
1
Resources