vite.config.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. rolldownOptions: {
  31. // occt-import-js (STEP previews, #2976) is an Emscripten build that
  32. // requires `path` and `crypto`, but only inside its ENVIRONMENT_IS_NODE
  33. // branches; in the browser it takes the fetch/getRandomValues paths.
  34. // Vite externalizes both and warns on every build. Drop just those two
  35. // warnings for that one package so a new externalization still shows.
  36. onLog(level, log, defaultHandler) {
  37. if (
  38. level === 'warn' &&
  39. /Module "(path|crypto)" has been externalized for browser compatibility, imported by "[^"]*\/node_modules\/occt-import-js\//.test(
  40. log.message,
  41. )
  42. ) {
  43. return
  44. }
  45. defaultHandler(level, log)
  46. },
  47. },
  48. },
  49. server: {
  50. host: '0.0.0.0',
  51. proxy: {
  52. '/api/v1/ws': {
  53. target: backendUrl,
  54. ws: true,
  55. changeOrigin: true,
  56. },
  57. '/api': {
  58. target: backendUrl,
  59. changeOrigin: true,
  60. },
  61. },
  62. },
  63. resolve: {
  64. alias: {
  65. '@': path.resolve(__dirname, './src'),
  66. },
  67. },
  68. })