Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wasmModule option to initialize JS API #2155

Merged
merged 4 commits into from Apr 6, 2022
Merged

add wasmModule option to initialize JS API #2155

merged 4 commits into from Apr 6, 2022

Conversation

evanw
Copy link
Owner

@evanw evanw commented Apr 6, 2022

The initialize JS API must be called when using esbuild in the browser to provide the WebAssembly module for esbuild to use. Previously the only way to do that was using the wasmURL API option like this:

await esbuild.initialize({
  wasmURL: '/node_modules/esbuild-wasm/esbuild.wasm',
})
console.log(await esbuild.transform('1+2'))

With this PR, you can now also initialize esbuild using a WebAssembly.Module instance using the wasmModule API option instead. The example above is equivalent to the following code:

await esbuild.initialize({
  wasmModule: await WebAssembly.compileStreaming(fetch('/node_modules/esbuild-wasm/esbuild.wasm'))
})
console.log(await esbuild.transform('1+2'))

This could be useful for environments where you want more control over how the WebAssembly download happens or where downloading the WebAssembly module is not possible.

Fixes #1093

@evanw evanw merged commit 44d70d3 into master Apr 6, 2022
@evanw evanw deleted the issues/1093 branch April 6, 2022 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support global instance of a WASM binary vs wasmURL reference (for say Cloudflare Worker environments)
1 participant