vite.config.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import path from 'path';
  2. import { defineConfig, loadEnv } from 'vite';
  3. import react from '@vitejs/plugin-react';
  4. export default defineConfig(({ mode }) => {
  5. const env = loadEnv(mode, '.', '');
  6. return {
  7. server: {
  8. port: 3000,
  9. host: '0.0.0.0',
  10. },
  11. plugins: [react()],
  12. define: {
  13. 'process.env.API_KEY': JSON.stringify(env.GEMINI_API_KEY),
  14. 'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY)
  15. },
  16. resolve: {
  17. alias: {
  18. '@': path.resolve(__dirname, '.'),
  19. }
  20. },
  21. build: {
  22. rollupOptions: {
  23. output: {
  24. manualChunks: {
  25. // React 核心
  26. 'vendor-react': ['react', 'react-dom', 'react-router-dom'],
  27. // Markdown 渲染相关
  28. 'vendor-markdown': ['react-markdown', 'remark-gfm'],
  29. // 代码高亮 (最大的包)
  30. 'vendor-syntax': ['react-syntax-highlighter'],
  31. // Excel 处理
  32. 'vendor-xlsx': ['xlsx'],
  33. // 图标库
  34. 'vendor-icons': ['lucide-react'],
  35. }
  36. }
  37. },
  38. // 可选:调整警告阈值
  39. chunkSizeWarningLimit: 600,
  40. },
  41. test: {
  42. globals: true,
  43. environment: 'jsdom',
  44. setupFiles: ['./tests/setup.ts'],
  45. }
  46. };
  47. });