feat(wasm): universal support with esm import syntax #2017
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
β Type of change
π Description
This PR unifies WASM support using Nitro's built-in wasm plugin and simplified ESM import syntax: (Following ES Module Integration Proposal for WebAssembly)
Using dynamic imports:
Using static imports: (1)
.wasm
imports, Nitro by default creates a base64 inlined version (in a chunk) and instantiates the module(1) One of the main blockers, are worker targets that don't support top level await, combined with rollup limitation with
inlineDynamicImports
we cannot use top level await forawait WebAssembly.instantiate
. This mainly affects/breaks Vercel Edge target. Internally we supportwasm.lazy
flag that causes to avoid depending on top-level wait for maximise compatibility. It requires static import slight syntax change to work universally again:The value of
_mod
is a virtual Promise-like that lazily get's evaluated. Hopefully at some point we don't require this syntax change too.π Checklist