From baa42fa625115d8f5771ca1d9aaf8c1f4116f2f6 Mon Sep 17 00:00:00 2001 From: Momentry Studio Date: Sat, 25 Jul 2026 13:35:41 +0800 Subject: [PATCH] feat: add build version display to all views Add build version indicator to verify code updates: 1. Create BuildVersion.vue component: - Displays in top-right corner (fixed position) - Format: YYYYMMDDHHMMSS-gitHash - Example: 20260725133504-39ce37e 2. Update vite.config.ts: - Inject __BUILD_VERSION__ global variable - Generated from build time + git commit hash 3. Add to App.vue: - Shown on all views automatically - Z-index: 9999 (always visible) 4. Add vite-env.d.ts: - TypeScript declarations for __BUILD_VERSION__ Purpose: - User can verify if browser loaded latest code - Easy to confirm updates are deployed - No need to check source code Location: Top-right corner, fixed position Format: Monospace font, small text, subtle styling --- src/components/BuildVersion.vue | 22 ++++++++++++++++++++++ src/vite-env.d.ts | 11 +++++++++++ vite.config.ts | 8 ++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/components/BuildVersion.vue create mode 100644 src/vite-env.d.ts diff --git a/src/components/BuildVersion.vue b/src/components/BuildVersion.vue new file mode 100644 index 0000000..fb4b904 --- /dev/null +++ b/src/components/BuildVersion.vue @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..b8f1d9e --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1,11 @@ +/// + +declare const __BUILD_VERSION__: string + +interface ImportMetaEnv { + readonly VITE_APP_TITLE: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 64cb2b4..1d1f1ae 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,9 +1,17 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' +import { execSync } from 'child_process' + +const gitHash = execSync('git log --format="%h" -1', { encoding: 'utf-8' }).trim() +const buildTime = new Date().toISOString().slice(0, 19).replace(/[-:T]/g, '') +const buildVersion = `${buildTime}-${gitHash}` export default defineConfig({ plugins: [vue()], + define: { + __BUILD_VERSION__: JSON.stringify(buildVersion) + }, resolve: { alias: { '@': resolve(__dirname, 'src')