From dea364c2a692c0bfcb4f435be3faf44972535f58 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 13 Nov 2025 18:47:19 -0600 Subject: [PATCH] Use esbuild worker, emit wasm file in build --- index.html | 2 +- src/lib/build/index.ts | 2 +- src/lib/esbuild.ts | 11 ++++++----- vite.config.ts | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 02083e67..1ced1476 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,7 @@ - + diff --git a/src/lib/build/index.ts b/src/lib/build/index.ts index 77833cf0..de24958c 100644 --- a/src/lib/build/index.ts +++ b/src/lib/build/index.ts @@ -24,7 +24,7 @@ async function bundle( options: BuildProjectOptions, ): Promise> { const { fs, projectPath, domParser, target = "esnext", esmUrl } = options; - const esbuild = await getEsbuild(esmUrl); + const esbuild = await getEsbuild(); const indexHtmlText = await fs.readFile( `${projectPath}/index.html`, diff --git a/src/lib/esbuild.ts b/src/lib/esbuild.ts index b051c1e9..227c5619 100644 --- a/src/lib/esbuild.ts +++ b/src/lib/esbuild.ts @@ -1,22 +1,23 @@ import type _ESBuild from "esbuild-wasm"; +import wasmUrl from "esbuild-wasm/esbuild.wasm?url" with { type: "url" }; type ESBuild = typeof _ESBuild; let promise: Promise | undefined; -export function getEsbuild(esmUrl: string): Promise { +export function getEsbuild(): Promise { if (!promise) { - promise = loadEsbuild(esmUrl); + promise = loadEsbuild(); } return promise; } -async function loadEsbuild(esmUrl: string): Promise { +async function loadEsbuild(): Promise { const { default: esbuild } = await import("esbuild-wasm"); await esbuild.initialize({ - worker: false, - wasmURL: `${esmUrl}/esbuild-wasm@0.25.8/esbuild.wasm`, + worker: true, + wasmURL: wasmUrl, }); return esbuild; diff --git a/vite.config.ts b/vite.config.ts index 1a75e9cd..6a981e21 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -33,7 +33,7 @@ export default defineConfig(() => ({ manifest: false, // Use existing manifest.webmanifest from public folder workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,wasm,mp3}'], - maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10 MB + maximumFileSizeToCacheInBytes: 15 * 1024 * 1024, // 15 MB (to accommodate esbuild.wasm at ~12 MB) cleanupOutdatedCaches: true, }, devOptions: {