Use esbuild worker, emit wasm file in build

This commit is contained in:
Alex Gleason committed 2025-11-13 18:50:46 -06:00
1 parent eabba1ecec
commit dea364c2a6
4 files changed
+9 -8

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@
<meta property="og:title" content="Shakespeare - Open Source AI Builder">
<meta property="og:description" content="Build custom apps with AI assistance using Shakespeare, an open-source development environment">
<meta property="og:image" content="https://shakespeare.diy/og-image.png">
<meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src 'self' https:; font-src 'self'; base-uri 'self'; manifest-src 'self'; connect-src 'self' blob: https: http: wss: ws:; img-src 'self' data: blob: https:; media-src 'self' https:">
<meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src 'self' https:; font-src 'self'; worker-src 'self' blob:; base-uri 'self'; manifest-src 'self'; connect-src 'self' blob: https: http: wss: ws:; img-src 'self' data: blob: https:; media-src 'self' https:">
<link rel="icon" type="image/png" href="/shakespeare-192x192.png">
<link rel="apple-touch-icon" href="/shakespeare-192x192.png" sizes="192x192">
<meta name="theme-color" content="#2b0037">
+1 -1
View File
@@ -24,7 +24,7 @@ async function bundle(
options: BuildProjectOptions,
): Promise<Record<string, Uint8Array>> {
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`,
+6 -5
View File
@@ -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<ESBuild> | undefined;
export function getEsbuild(esmUrl: string): Promise<ESBuild> {
export function getEsbuild(): Promise<ESBuild> {
if (!promise) {
promise = loadEsbuild(esmUrl);
promise = loadEsbuild();
}
return promise;
}
async function loadEsbuild(esmUrl: string): Promise<ESBuild> {
async function loadEsbuild(): Promise<ESBuild> {
const { default: esbuild } = await import("esbuild-wasm");
await esbuild.initialize({
worker: false,
wasmURL: `${esmUrl}/[email protected]/esbuild.wasm`,
worker: true,
wasmURL: wasmUrl,
});
return esbuild;
+1 -1
View File
@@ -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: {