Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion application/ui/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,40 @@ export default defineConfig({
...config,
resolve: { ...config.resolve, extensions },
watchOptions: { ...config.watchOptions, ignored: ['**/src-tauri/**'] },
// opencv.js (emscripten, under src/ so it's parsed) references
// `__dirname` for Node environment detection. Rspack's default
// `warn-mock` mocks it to '/' AND warns on every build. In the
// browser opencv takes the non-Node code path, so the mock value
// is never used — switch to 'mock' to keep the (identical) runtime
// behavior without the noisy build warning.
node: { ...config.node, __dirname: 'mock', __filename: 'mock' },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we ignore the warnings from opencv? I think that might be safe because of:

// The vendored @geti/smart-tools OpenCV.js build (Emscripten-generated,
// cloned in by clone-geti-ui-packages and not ours to edit) contains
// __dirname/__filename in its Node-environment-detection boilerplate.
// It's dead code in a web build (guarded by an ENVIRONMENT_IS_NODE
// check) but Rspack still statically parses and warns on it. Scope
// the suppression to just this file so any future first-party/new
// dependency __dirname usage still surfaces a warning.
ignoreWarnings: [...(config.ignoreWarnings ?? []), { module: /smart-tools[\\/]src[\\/]opencv/ }]

optimization: {
...config.optimization,
// Force deterministic (numeric) chunk IDs in dev too. Rspack's
// dev default is `chunkIds: 'named'`, which makes our module
// web workers (SAM / intelligent-scissors / SSIM) request a
// shared async vendor chunk by a long derived name
// (`vendors-node_modules_onnxruntime-web…polylabel_js.js`) that
// is never emitted under that name -> the dev server's SPA
// fallback returns index.html -> the worker's importScripts
// fails with "MIME type ('text/html') is not executable".
// Production already uses deterministic IDs (numeric chunks),
// which is why `npm run build` is unaffected. Matching dev to
// production keeps the worker chunk names consistent.
chunkIds: 'deterministic',
},
};
},
},
server: {
headers: {
'Cross-Origin-Embedder-Policy': 'credentialless',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cache-Control': 'public, max-age=31536000, immutable',
// Must NOT be 'immutable': dev async chunks are not content-hashed, so an
// immutable cache causes the browser to keep serving stale chunk/HMR runtime
// URLs after a rebuild (stale worker imports, mismatched hmr.js client). See
// /memories/repo/dev-server-immutable-cache-stale-worker.md.
Comment thread
jpggvilaca marked this conversation as resolved.
Outdated
'Cache-Control': 'no-cache',
'Content-Security-Policy':
"default-src 'self'; " +
"script-src 'self' 'unsafe-eval' blob:; " +
Expand Down
Loading