vite.config.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import type { ProxyOptions } from 'vite'
  4. import { resolve } from 'path'
  5. import pkg from './package.json'
  6. const FRONTEND_PORT = Number(process.env.YAOYAO_WEBUI_FRONTEND_PORT || process.env.HERMES_WEB_UI_FRONTEND_PORT || 8649)
  7. const BACKEND_PORT = process.env.YAOYAO_WEBUI_BACKEND_PORT || process.env.HERMES_WEB_UI_BACKEND_PORT || '8648'
  8. const BACKEND = `http://127.0.0.1:${BACKEND_PORT}`
  9. function createProxyConfig(): ProxyOptions {
  10. return {
  11. target: BACKEND,
  12. changeOrigin: true,
  13. ws: true,
  14. configure: (proxy) => {
  15. proxy.on('proxyReq', (proxyReq) => {
  16. proxyReq.removeHeader('origin')
  17. proxyReq.removeHeader('referer')
  18. })
  19. proxy.on('proxyReqWs', (proxyReq) => {
  20. proxyReq.removeHeader('origin')
  21. proxyReq.removeHeader('referer')
  22. })
  23. proxy.on('proxyRes', (proxyRes) => {
  24. proxyRes.headers['cache-control'] = 'no-cache'
  25. proxyRes.headers['x-accel-buffering'] = 'no'
  26. })
  27. },
  28. }
  29. }
  30. export default defineConfig({
  31. root: 'packages/client',
  32. plugins: [vue()],
  33. define: {
  34. __APP_VERSION__: JSON.stringify(pkg.version),
  35. },
  36. resolve: {
  37. alias: {
  38. '@': resolve(__dirname, 'packages/client/src'),
  39. },
  40. },
  41. build: {
  42. outDir: '../../dist/client',
  43. emptyOutDir: true,
  44. // Use esbuild for minification (much faster than terser)
  45. minify: 'esbuild',
  46. // Disable sourcemap generation for faster builds
  47. sourcemap: false,
  48. target: 'es2020',
  49. // Increase chunk size warning limit (default: 500KB)
  50. chunkSizeWarningLimit: 1000,
  51. // CSS code splitting for better caching
  52. cssCodeSplit: true,
  53. rollupOptions: {
  54. output: {
  55. // Optimize chunk file names for better caching
  56. chunkFileNames: 'assets/js/[name]-[hash].js',
  57. entryFileNames: 'assets/js/[name]-[hash].js',
  58. assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
  59. },
  60. },
  61. },
  62. optimizeDeps: {
  63. // Pre-bundle all large dependencies for faster builds
  64. include: [
  65. 'monaco-editor',
  66. 'mermaid',
  67. 'vue',
  68. 'vue-router',
  69. 'pinia',
  70. 'naive-ui',
  71. ],
  72. },
  73. server: {
  74. port: FRONTEND_PORT,
  75. strictPort: true,
  76. proxy: {
  77. '/api': createProxyConfig(),
  78. '/v1': createProxyConfig(),
  79. '/health': createProxyConfig(),
  80. '/upload': createProxyConfig(),
  81. '/webhook': createProxyConfig(),
  82. '/socket.io': {
  83. target: BACKEND,
  84. ws: true,
  85. },
  86. },
  87. },
  88. })
粤ICP备19079148号