vite.config.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { defineConfig, loadEnv } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'node:path'
  4. function parsePort(raw: string | undefined, fallback: number): number {
  5. const n = Number.parseInt(String(raw ?? '').trim(), 10)
  6. if (!Number.isFinite(n) || n < 1 || n > 65535) return fallback
  7. return n
  8. }
  9. export default defineConfig(({ mode }) => {
  10. const env = loadEnv(mode, process.cwd(), '')
  11. const backendPort = parsePort(
  12. process.env.BACKEND_PORT || env.BACKEND_PORT || env.VITE_BACKEND_PORT,
  13. 8000,
  14. )
  15. const frontendPort = parsePort(
  16. process.env.FRONTEND_PORT || env.FRONTEND_PORT || env.VITE_DEV_PORT,
  17. 5173,
  18. )
  19. const backend = `http://127.0.0.1:${backendPort}`
  20. return {
  21. plugins: [vue()],
  22. resolve: { alias: { '@': resolve(process.cwd(), 'src') } },
  23. server: {
  24. host: '127.0.0.1',
  25. port: frontendPort,
  26. strictPort: true,
  27. open: '/',
  28. proxy: {
  29. '/api': { target: backend, changeOrigin: true, timeout: 420000, proxyTimeout: 420000 },
  30. '/health': { target: backend, changeOrigin: true, timeout: 420000, proxyTimeout: 420000 },
  31. },
  32. },
  33. build: {
  34. rollupOptions: {
  35. output: {
  36. manualChunks(id) {
  37. if (id.includes('node_modules/ant-design-vue')) {
  38. if (id.includes('/vc-table/') || id.includes('/table/')) return 'antd-table'
  39. if (id.includes('/vc-select/') || id.includes('/select/')) return 'antd-select'
  40. if (id.includes('/vc-picker/') || id.includes('/date-picker/')) return 'antd-picker'
  41. return 'antd'
  42. }
  43. if (id.includes('node_modules/katex')) return 'katex'
  44. },
  45. },
  46. },
  47. },
  48. }
  49. })