mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Load esbuild-wasm more efficiently, fix tests
This commit is contained in:
1 parent
b3ce6979c4
commit
ebc180a850
2 files changed
+25
-7
No files matched your search
@@ -1,15 +1,10 @@
|
||||
import * as esbuild from "esbuild-wasm";
|
||||
import { getEsbuild } from "@/lib/esbuild";
|
||||
|
||||
import { esmPlugin } from "./esmPlugin";
|
||||
import { fsPlugin } from "./fsPlugin";
|
||||
|
||||
import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
||||
|
||||
const esbuildInitPromise = esbuild.initialize({
|
||||
worker: false,
|
||||
wasmURL: "https://esm.sh/[email protected]/esbuild.wasm",
|
||||
});
|
||||
|
||||
export interface BuildProjectOptions {
|
||||
fs: JSRuntimeFS;
|
||||
projectPath: string;
|
||||
@@ -20,7 +15,7 @@ export interface BuildProjectOptions {
|
||||
export async function buildProject(
|
||||
options: BuildProjectOptions,
|
||||
): Promise<Record<string, Uint8Array>> {
|
||||
await esbuildInitPromise;
|
||||
const esbuild = await getEsbuild();
|
||||
|
||||
const { fs, projectPath, domParser, target } = options;
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import type _ESBuild from "esbuild-wasm";
|
||||
|
||||
type ESBuild = typeof _ESBuild;
|
||||
|
||||
let promise: Promise<ESBuild> | undefined;
|
||||
|
||||
export function getEsbuild(): Promise<ESBuild> {
|
||||
if (!promise) {
|
||||
promise = loadEsbuild();
|
||||
}
|
||||
return promise;
|
||||
}
|
||||
|
||||
async function loadEsbuild(): Promise<ESBuild> {
|
||||
const { default: esbuild } = await import("esbuild-wasm");
|
||||
|
||||
await esbuild.initialize({
|
||||
worker: false,
|
||||
wasmURL: "https://esm.sh/[email protected]/esbuild.wasm",
|
||||
});
|
||||
|
||||
return esbuild;
|
||||
}
|
||||
Reference in new issue
Block a user