diff --git a/README.md b/README.md index f6be580..05b0e7c 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,11 @@ builds because Vite owns the `.wasm` asset URL. ## Usage in inline workers (`?worker&inline`) -Vite inline workers are loaded from `blob:` URLs, so sibling `.wasm` files cannot be resolved -from `import.meta.url`. Fetch the wasm bytes on the main thread and pass them into the worker: +Vite inline workers are loaded from `blob:` URLs, so neither sibling `.wasm` files nor sibling +JS chunks can be resolved relative to the worker. To keep inline workers self-contained, the +Emscripten glue is imported **statically** (not via a runtime `import("./wasm-zstd.js")`), so +bundlers inline it into the worker chunk. You only need to supply the wasm **bytes** — fetch +them on the main thread and pass them into the worker: ```ts // main thread diff --git a/package.json b/package.json index a1dd85a..1bbaec7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ioai/wasm-zstd", - "version": "1.1.1", + "version": "1.1.2", "description": "Vite-friendly WebAssembly bindings for facebook/zstd", "type": "module", "main": "dist/index.js", diff --git a/src/index.js b/src/index.js index 2f93816..95e9673 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ -let createModulePromise; +import createModule from "./wasm-zstd.js"; + let modulePromise; let moduleInstance; @@ -49,18 +50,12 @@ function normalizeInitOptions(options = {}) { return moduleOptions; } -async function loadCreateModule() { - createModulePromise ??= import("./wasm-zstd.js").then((mod) => mod.default); - return await createModulePromise; -} - export async function init(options = {}) { if (moduleInstance != undefined) { return; } const moduleOptions = normalizeInitOptions(options); - const createModule = await loadCreateModule(); modulePromise ??= createModule(moduleOptions).then((mod) => { moduleInstance = mod;