Vite
Vite is the foundation for SvelteKit, Nuxt, Astro, SolidStart, and Vite-based React.
TL;DR
Call createWasmFactory() as in Quickstart. For plain Vite,
this config plus a self-hosted worker (below) is all that's needed.
SvelteKit / Nuxt: headers on the document
server.headers only covers assets Vite serves directly. Frameworks that
serve their own HTML document (SvelteKit, Nuxt, Astro SSR) bypass it, so the
document loads without COOP/COEP, crossOriginIsolated is false, and the
engine refuses to boot - in dev too.
Set the headers with middleware that runs on every response:
Add coiHeaders() to plugins. In production your host must send the same two
headers on the document too (adapter / CDN / reverse proxy).
Self-hosting the worker
A Vite production build inlines the worker as a data: URL, which breaks its
internal imports (onykia-engine: worker error, zero pages). Dev is fine; the
build is not. The fix is to serve the assets yourself:
-
Copy
node_modules/@mudomi/onykia-engine/dist/wasm/(the whole tree, includingsnippets/) into a served directory -static/for SvelteKit,public/for plain Vite - via a build script. -
Point the factory at the stable URLs:
Troubleshooting
| Console message | Cause | Fix |
|---|---|---|
requires a cross-origin-isolated host page / SharedArrayBuffer is not defined | Document not isolated | COOP/COEP on every response, document included (middleware above) |
onykia-engine: worker error (build only, dev fine) | Worker inlined as data: URL | Self-host the worker + explicit factory URLs |
optimized info should be defined / 404 under .vite/deps/ | Dep-optimizer mangled the asset URLs | optimizeDeps.exclude, then delete node_modules/.vite and restart |
Worker fails with an import syntax error | Worker emitted as a classic worker | worker: { format: 'es' } |
After changing optimizeDeps, delete node_modules/.vite and restart - Vite
caches optimizer results and won't re-run on config change alone.