From ef34a1bb5de7798cd347c0dc6f018fe80eb36c0f Mon Sep 17 00:00:00 2001 From: CHE LIANG ZHAO Date: Mon, 26 Jan 2026 16:24:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Vite=20allow=20list?= =?UTF-8?q?=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/app.d.ts | 3 +++ web/src/lib/version.ts | 3 --- web/src/routes/+layout.svelte | 6 +++--- web/vite.config.ts | 8 ++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 web/src/lib/version.ts diff --git a/web/src/app.d.ts b/web/src/app.d.ts index da08e6d..f01361b 100644 --- a/web/src/app.d.ts +++ b/web/src/app.d.ts @@ -8,6 +8,9 @@ declare global { // interface PageState {} // interface Platform {} } + + // Vite 注入的全局变量 + const __APP_VERSION__: string; } export {}; diff --git a/web/src/lib/version.ts b/web/src/lib/version.ts deleted file mode 100644 index 1196837..0000000 --- a/web/src/lib/version.ts +++ /dev/null @@ -1,3 +0,0 @@ -// 版本号配置 -// 更新版本时需要手动修改此文件 -export const VERSION = '1.3.0'; diff --git a/web/src/routes/+layout.svelte b/web/src/routes/+layout.svelte index 8927faa..e2723dd 100644 --- a/web/src/routes/+layout.svelte +++ b/web/src/routes/+layout.svelte @@ -27,8 +27,8 @@ import Sparkles from '@lucide/svelte/icons/sparkles'; import Info from '@lucide/svelte/icons/info'; - // 版本号 - import { VERSION } from '$lib/version'; + // 版本号(从 Vite 编译时注入) + const appVersion = __APP_VERSION__; // Theme import { @@ -248,7 +248,7 @@ title="查看更新日志" > - v{VERSION} + v{appVersion} {/snippet} diff --git a/web/vite.config.ts b/web/vite.config.ts index 88629ba..0b2d0ac 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -2,10 +2,18 @@ import { defineConfig } from 'vitest/config'; import { playwright } from '@vitest/browser-playwright'; import { sveltekit } from '@sveltejs/kit/vite'; import tailwindcss from '@tailwindcss/vite'; +import { readFileSync } from 'fs'; +import { fileURLToPath } from 'url'; + +const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')); export default defineConfig({ plugins: [sveltekit(), tailwindcss()], + define: { + __APP_VERSION__: JSON.stringify(pkg.version) + }, + server: { proxy: { '/api': {