fix: better handle wasm loading on node and browser

This commit is contained in:
Derrick Hammer 2023-06-23 23:41:27 -04:00
parent a9e94ba896
commit 23c8244a68
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,5 @@
// @ts-ignore
import baoWasm from "./wasm/bao.wasm";
import baoWasm from "./wasm.js";
import Go from "./go_wasm.js";
export async function getVerifiableStream(

16
src/wasm.ts Normal file
View File

@ -0,0 +1,16 @@
import isNode from "detect-node";
export default async function (imports) {
if (isNode) {
const fs = await import("fs/promises");
// @ts-ignore
const wasmPath = new URL("wasm/bao.wasm", import.meta.url);
const wasm = await fs.readFile(wasmPath);
return WebAssembly.instantiate(wasm, imports);
}
// @ts-ignore
return await import("./wasm/bao.wasm");
}