import { defineConfig, mergeConfig } from 'vite'; import { minwebide } from 'minwebide/vite'; // Cross-origin isolation makes SharedArrayBuffer available (numbl uses it // for pause()/sleep timing). Dev/preview get it from plain response headers — // no service worker involved. Production builds are for GitHub Pages, which // can't set headers, so only there the coi-serviceworker is injected (the // same approach numbl.org uses). const coiHeaders = { 'Cross-Origin-Embedder-Policy': 'require-corp', 'Cross-Origin-Opener-Policy': 'same-origin', }; const injectCoiServiceWorker = { name: 'inject-coi-serviceworker', apply: 'build' as const, transformIndexHtml() { // relative src so it resolves under the DEPLOY_BASE sub-path return [{ tag: 'script', attrs: { src: 'coi-serviceworker.js' }, injectTo: 'head' as const }]; }, }; // DEPLOY_BASE is set by CI when building for GitHub Pages // (the site is served from /numbl-web-ide/, not the domain root). export default defineConfig(mergeConfig(minwebide(), { base: process.env.DEPLOY_BASE ?? '/', plugins: [injectCoiServiceWorker], server: { headers: coiHeaders }, preview: { headers: coiHeaders }, }));