Skip to content

feat(wasm): support inlining wasm binaries with the ?inline query - #1909

Open
elecmonkey wants to merge 4 commits into
mainfrom
elecmonkey/wasm-inline
Open

elecmonkey wants to merge 4 commits into
mainfrom
elecmonkey/wasm-inline

Conversation

@elecmonkey

@elecmonkey elecmonkey commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary

Support importing small WebAssembly binaries with ?inline to embed them directly into JavaScript.

import { add } from './add.wasm?inline';

export const sum = (a, b) => add(a, b);

The binary is instantiated with top-level await and exposes both named exports and a default export of instance.exports. This requires ESM output.

In bundleless builds, the binary is embedded into each importing JavaScript file. WebAssembly imports are resolved as module dependencies.

@huanglinfei091-cmd

This comment was marked as off-topic.

@elecmonkey
elecmonkey force-pushed the elecmonkey/wasm-inline branch 2 times, most recently from e93a071 to 80cadfa Compare September 13, 2026 21:22
@elecmonkey
elecmonkey marked this pull request as ready for review September 13, 2026 21:33
Copilot AI lite review requested due to automatic review settings September 13, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@elecmonkey
elecmonkey force-pushed the elecmonkey/wasm-inline branch from 80cadfa to ebd1d43 Compare September 14, 2026 03:26
Comment thread packages/core/src/wasm/inlineLoader.ts
Comment thread packages/core/src/wasm/compose.ts Outdated
Comment thread packages/core/src/wasm/compose.ts Outdated
@Timeless0911

Copy link
Copy Markdown
Contributor

no documents about inline feature in wasm chapter?

The resolve hook read an existing issuer query off the request before
appending a new one, but appended unconditionally. Requests reaching the
hook never carry that query, so drop the fallback.
The inline loader rule was registered regardless of the wasm mode, so
`wasm: false` still inlined `?inline` imports while leaving plain `.wasm`
imports alone. Skip the rule and keep the original specifiers instead.
Absolute issuer paths ended up in the generated module identifiers of
bundleless output, which made builds depend on the source directory.
const { format } = this.getOptions();
if (format !== 'esm') {
throw new Error(
`Importing wasm with the "?inline" query only supports the "esm" format, but the current format is "${format}".`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`Importing wasm with the "?inline" query only supports the "esm" format, but the current format is "${format}".`,
`WASM imports with "?inline" require the "esm" format, but the current format is "${format}".`,

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.

4 participants