File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -43,8 +43,11 @@ builds because Vite owns the `.wasm` asset URL.
4343
4444## Usage in inline workers (` ?worker&inline ` )
4545
46- Vite inline workers are loaded from ` blob: ` URLs, so sibling ` .wasm ` files cannot be resolved
47- from ` import.meta.url ` . Fetch the wasm bytes on the main thread and pass them into the worker:
46+ Vite inline workers are loaded from ` blob: ` URLs, so neither sibling ` .wasm ` files nor sibling
47+ JS chunks can be resolved relative to the worker. To keep inline workers self-contained, the
48+ Emscripten glue is imported ** statically** (not via a runtime ` import("./wasm-zstd.js") ` ), so
49+ bundlers inline it into the worker chunk. You only need to supply the wasm ** bytes** — fetch
50+ them on the main thread and pass them into the worker:
4851
4952``` ts
5053// main thread
Original file line number Diff line number Diff line change 11{
22 "name" : " @ioai/wasm-zstd" ,
3- "version" : " 1.1.1 " ,
3+ "version" : " 1.1.2 " ,
44 "description" : " Vite-friendly WebAssembly bindings for facebook/zstd" ,
55 "type" : " module" ,
66 "main" : " dist/index.js" ,
Original file line number Diff line number Diff line change 1- let createModulePromise ;
1+ import createModule from "./wasm-zstd.js" ;
2+
23let modulePromise ;
34let moduleInstance ;
45
@@ -49,18 +50,12 @@ function normalizeInitOptions(options = {}) {
4950 return moduleOptions ;
5051}
5152
52- async function loadCreateModule ( ) {
53- createModulePromise ??= import ( "./wasm-zstd.js" ) . then ( ( mod ) => mod . default ) ;
54- return await createModulePromise ;
55- }
56-
5753export async function init ( options = { } ) {
5854 if ( moduleInstance != undefined ) {
5955 return ;
6056 }
6157
6258 const moduleOptions = normalizeInitOptions ( options ) ;
63- const createModule = await loadCreateModule ( ) ;
6459
6560 modulePromise ??= createModule ( moduleOptions ) . then ( ( mod ) => {
6661 moduleInstance = mod ;
You can’t perform that action at this time.
0 commit comments