load worker as a module
This commit is contained in:
parent
03c7d1eff1
commit
f50f02b9c5
1 changed files with 9 additions and 10 deletions
|
|
@ -11,18 +11,17 @@ export async function loadFile(path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createWorker() {
|
export async function createWorker() {
|
||||||
// Combine wasmExecJs with worker script
|
let response = await fetch(new URL("./worker.js", import.meta.url));
|
||||||
const workerResponse = await fetch(new URL("./worker.js", import.meta.url));
|
if (!response.ok)
|
||||||
if (!workerResponse.ok) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Failed to load worker.js: ${workerResponse.status} ${workerResponse.statusText}`
|
`Failed to load worker.js: ${response.status} ${response.statusText}`
|
||||||
);
|
);
|
||||||
}
|
let workerScript = await response.text();
|
||||||
const workerJs = await workerResponse.text();
|
|
||||||
|
|
||||||
const blob = new Blob(["(() => {", wasmExecJs, "})();", workerJs], {
|
let blob = new Blob(["(() => {", wasmExecJs, "})();", workerScript], {
|
||||||
type: "application/javascript",
|
type: "text/javascript;charset=utf-8",
|
||||||
|
});
|
||||||
|
return new Worker(URL.createObjectURL(blob), {
|
||||||
|
type: "module",
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Worker(URL.createObjectURL(blob));
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue