@almeidx/version-check-vite
v1.0.0
Published
Vite plugin for @almeidx/version-check.
Maintainers
Readme
@almeidx/version-check-vite
Vite plugin for @almeidx/version-check.
This package resolves one build id for a Vite app, injects it into client code, emits version.json during builds, serves the same payload in dev, and re-exports the core API.
Install
pnpm add @almeidx/version-check-viteUsage
Add the plugin to vite.config.ts:
import { versionCheck } from "@almeidx/version-check-vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [versionCheck()],
});Read the matching build id from the virtual module:
import { createVersionChecker } from "@almeidx/version-check-vite";
import buildId from "virtual:version-check/build-id";
createVersionChecker({
currentVersion: buildId,
});For TypeScript, reference the virtual module types from your app env file:
import "@almeidx/version-check-vite/virtual";Version endpoint
The plugin emits dist/version.json during builds and serves /version.json during dev. Both contain the same build id that the virtual module exposes:
{
"buildId": "2026-06-01T12-00-00Z"
}The generated buildId uses an explicit buildId or resolveBuildId option, VERSION_CHECK_BUILD_ID, SOURCE_COMMIT, VERCEL_GIT_COMMIT_SHA, CI_COMMIT_SHA, GITHUB_SHA, or local-dev.
Options
versionCheck({
buildId: process.env.MY_BUILD_ID,
fileName: "version.json",
define: true,
});buildIdoverrides automatic resolution.resolveBuildIdprovides a custom resolver when you want to read from another explicit source.fileNamechanges the emitted and served JSON asset name.defineopts into a Vite global constant. Passtruefor__VERSION_CHECK_BUILD_ID__or a string for a custom constant name.
versionCheck({
resolveBuildId: () => process.env.MY_DEPLOY_ID,
});License
Apache-2.0
