mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Use esbuild worker, emit wasm file in build
This commit is contained in:
4 files changed
+9
-8
No files matched your search
@@ -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
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user