import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; const API_TARGET = 'http://localhost:3000'; /** * 版本号唯一来源:`web-server/package.json`(与 `GET /health` 的 version 同源)。 * 构建期注入 `__APP_VERSION__`,管理端左下角直接展示,避免代码里再手写一份 * (见开发文档 v1.5 第十一章「版本号展示」)。 */ const serverPackage = JSON.parse( readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'), ) as { version?: string }; const APP_VERSION = serverPackage.version ?? '0.0.0'; // base './' 让产物可挂在任意子路径;开发期 /api 与 /health 代理到 NestJS 服务。 export default defineConfig({ base: './', define: { __APP_VERSION__: JSON.stringify(APP_VERSION), }, plugins: [react()], server: { port: 5173, strictPort: true, proxy: { '/api': { target: API_TARGET, changeOrigin: true, }, '/health': { target: API_TARGET, changeOrigin: true, }, }, }, build: { outDir: 'dist', sourcemap: false, // VRM 预览分包内是 three.js 本体(约 750 kB),属于预期体积。 chunkSizeWarningLimit: 900, }, });