vite.config.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { defineConfig } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. import path from 'path'
  4. // Backend port for dev server proxy (default: 8000)
  5. const backendPort = process.env.BACKEND_PORT || '8000'
  6. const backendUrl = `http://localhost:${backendPort}`
  7. export default defineConfig({
  8. // Default base ('/') emits absolute asset URLs (/assets/...). Required so
  9. // deep SPA routes (camera popup at /camera/<id>, /projects/<id>, kiosk
  10. // /spoolbuddy/ams, refresh on any nested route) resolve their <script>
  11. // and <link> tags to /assets/... instead of /<route-prefix>/assets/...,
  12. // which the SPA fallback would otherwise return as text/html and the
  13. // browser would refuse to execute (#1221). The earlier `base: ''` partial
  14. // fix for subpath reverse proxies (#1195, wontfix) is reverted — that
  15. // audience uses NPM + Cloudflare Tunnel at a real domain per the
  16. // documented workaround, which doesn't depend on this setting.
  17. plugins: [react()],
  18. build: {
  19. outDir: '../static',
  20. emptyOutDir: true,
  21. chunkSizeWarningLimit: 3000,
  22. },
  23. server: {
  24. host: '0.0.0.0',
  25. proxy: {
  26. '/api/v1/ws': {
  27. target: backendUrl,
  28. ws: true,
  29. changeOrigin: true,
  30. },
  31. '/api': {
  32. target: backendUrl,
  33. changeOrigin: true,
  34. },
  35. },
  36. },
  37. resolve: {
  38. alias: {
  39. '@': path.resolve(__dirname, './src'),
  40. },
  41. },
  42. })