Files
bambuddy/frontend/vite.config.ts
T
maziggy 86bd9e1bd4 fix(file-manager): harden the merged previews - PDF.js legacy build, server PDF thumbnails, STEP progress (issue #2976)
Follow-ups after merging PR #3128 (with the #2990 preview work):

- PDF preview failed on every browser without
  Map.prototype.getOrInsertComputed (Chrome < 145, Firefox < 144,
  older Safari): "This file cannot be previewed" for any PDF. Load
  pdf.js's legacy build, which bundles the polyfills for page and
  worker, and bundle the worker through Vite (?worker&url) so
  build.target lowers its class static block for Safari 16.0-16.3.
  The browser-baseline check only scanned .js output and never saw
  the copied .mjs worker; it scans .mjs too.
- PDF grid thumbnails only existed after someone opened the preview.
  Page one is now rendered server-side with PDFium (pypdfium2, new
  dependency, prebuilt wheels for every shipped platform) on upload,
  ZIP extraction and external-folder scans; Generate Thumbnails
  backfills PDFs as well. Renders are serialised behind a lock
  (PDFium is not thread-safe), run off the event loop, and scale
  from the page size so a huge MediaBox cannot allocate a huge
  bitmap. Unreadable PDFs land without a thumbnail and keep the
  browser fallback.
- A large STEP file takes over a minute to mesh in the browser and
  showed only a spinner. STEP loads now show "Converting STEP
  model... N s" and a note that large files can take a minute or
  more, in all 15 locales.
- Drop the two occt-import-js "externalized for browser
  compatibility" build warnings (path/crypto are only required in
  its Node branch); any other externalization still shows.
2026-09-26 09:51:52 +02:00

72 lines
2.6 KiB
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// Backend port for dev server proxy (default: 8000)
const backendPort = process.env.BACKEND_PORT || '8000'
const backendUrl = `http://localhost:${backendPort}`
export default defineConfig({
// Default base ('/') emits absolute asset URLs (/assets/...). Required so
// deep SPA routes (camera popup at /camera/<id>, /projects/<id>, kiosk
// /spoolbuddy/ams, refresh on any nested route) resolve their <script>
// and <link> tags to /assets/... instead of /<route-prefix>/assets/...,
// which the SPA fallback would otherwise return as text/html and the
// browser would refuse to execute (#1221). The earlier `base: ''` partial
// fix for subpath reverse proxies (#1195, wontfix) is reverted — that
// audience uses NPM + Cloudflare Tunnel at a real domain per the
// documented workaround, which doesn't depend on this setting.
plugins: [react()],
build: {
outDir: '../static',
emptyOutDir: true,
chunkSizeWarningLimit: 3000,
// Support floor is Safari 16.0 / iOS 16.0 (see
// scripts/check-browser-baseline.mjs, #2971). Without an explicit target
// the bundler keeps newer syntax verbatim — pdf.js ships class static
// initialisation blocks (Safari 16.4+), which would parse-fail the whole
// chunk on iOS 16.0-16.3 (#2976). This lowers such syntax at build time;
// regex features are NOT lowered, which is why the baseline check script
// still exists alongside this setting.
target: 'safari16',
rolldownOptions: {
// occt-import-js (STEP previews, #2976) is an Emscripten build that
// requires `path` and `crypto`, but only inside its ENVIRONMENT_IS_NODE
// branches; in the browser it takes the fetch/getRandomValues paths.
// Vite externalizes both and warns on every build. Drop just those two
// warnings for that one package so a new externalization still shows.
onLog(level, log, defaultHandler) {
if (
level === 'warn' &&
/Module "(path|crypto)" has been externalized for browser compatibility, imported by "[^"]*\/node_modules\/occt-import-js\//.test(
log.message,
)
) {
return
}
defaultHandler(level, log)
},
},
},
server: {
host: '0.0.0.0',
proxy: {
'/api/v1/ws': {
target: backendUrl,
ws: true,
changeOrigin: true,
},
'/api': {
target: backendUrl,
changeOrigin: true,
},
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
})