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': {