vite.config.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. // Support floor is Safari 16.0 / iOS 16.0 (see
  23. // scripts/check-browser-baseline.mjs, #2971). Without an explicit target
  24. // the bundler keeps newer syntax verbatim — pdf.js ships class static
  25. // initialisation blocks (Safari 16.4+), which would parse-fail the whole
  26. // chunk on iOS 16.0-16.3 (#2976). This lowers such syntax at build time;
  27. // regex features are NOT lowered, which is why the baseline check script
  28. // still exists alongside this setting.
  29. target: 'safari16',
  30. },
  31. server: {
  32. host: '0.0.0.0',
  33. proxy: {
  34. '/api/v1/ws': {
  35. target: backendUrl,
  36. ws: true,
  37. changeOrigin: true,
  38. },
  39. '/api': {
  40. target: backendUrl,
  41. changeOrigin: true,
  42. },
  43. },
  44. },
  45. resolve: {
  46. alias: {
  47. '@': path.resolve(__dirname, './src'),
  48. },
  49. },
  50. })