From c53ee0ed90db09921e01145a58fc2f5684171620 Mon Sep 17 00:00:00 2001 From: weishu Date: Wed, 20 May 2026 20:47:16 +0800 Subject: [PATCH] fix web vitest config loading --- web/vite.config.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/vite.config.ts b/web/vite.config.ts index 26a6adbd..58ab1422 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,11 +1,24 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { VitePWA } from 'vite-plugin-pwa' +import { readFileSync } from 'node:fs' import { resolve } from 'node:path' -import { APP_VERSION } from '@hapi/protocol/buildInfo' const base = process.env.VITE_BASE_URL || '/' const hubTarget = process.env.VITE_HUB_PROXY || 'http://127.0.0.1:3006' +const appVersion = readAppVersion() + +function readAppVersion(): string { + const buildInfoPath = resolve(__dirname, '../shared/src/buildInfo.ts') + const buildInfo = readFileSync(buildInfoPath, 'utf8') + const match = buildInfo.match(/export const APP_VERSION = ['"]([^'"]+)['"]/) + + if (!match) { + throw new Error(`Could not read APP_VERSION from ${buildInfoPath}`) + } + + return match[1] +} function getVendorChunkName(id: string): string | undefined { if (!id.includes('/node_modules/')) { @@ -33,7 +46,7 @@ function getVendorChunkName(id: string): string | undefined { export default defineConfig({ define: { - __APP_VERSION__: JSON.stringify(APP_VERSION), + __APP_VERSION__: JSON.stringify(appVersion), }, server: { host: true,