Mini-Plugin used to provide commit hash information to the project.
This should work cross-framework just fine.
pnpm i vite-plugin-commit-hash
- Load the plugin in your
vite.config.js
:import {CommitHashPlugin} from 'vite-plugin-commit-hash';
followed byplugins: [/*your other plugins*/, CommitHashPlugin({noPrefix:false,noVirtual:false})]
Import virtual:commit-hash
in your codebase;
import CommitHash from 'virtual:commit-hash';
console.log(CommitHash); // -> Current Hash - with '-dirty' at the end if there's uncommitted work.
import { sveltekit } from '@sveltejs/kit/vite';
import { CommitHashPlugin } from 'vite-plugin-commit-hash';
import type { UserConfig } from 'vite';
/** @type {import('vite').UserConfig} */
const config: UserConfig = {
plugins: [sveltekit(), CommitHashPlugin({noPrefix:false,noVirtual:false})]
};
export default config;
Developed by @ExponentialWorkload
Licensed under the MIT License
Slightly inspired by vite-plugin-git-revision