import path from 'path'; import { defineConfig, loadEnv } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig(({ mode }) => { const env = loadEnv(mode, '.', ''); return { server: { port: 3000, host: '0.0.0.0', }, plugins: [react()], define: { 'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY), 'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY) }, resolve: { alias: { '@': path.resolve(__dirname, '.'), } }, build: { rollupOptions: { output: { manualChunks: { // React 核心 'vendor-react': ['react', 'react-dom', 'react-router-dom'], // Markdown 渲染相关 'vendor-markdown': ['react-markdown', 'remark-gfm'], // 代码高亮 (最大的包) 'vendor-syntax': ['react-syntax-highlighter'], // Excel 处理 'vendor-xlsx': ['xlsx'], // 图标库 'vendor-icons': ['lucide-react'], } } }, // 可选:调整警告阈值 chunkSizeWarningLimit: 600, }, test: { globals: true, environment: 'jsdom', setupFiles: ['./tests/setup.ts'], } }; });