Skip to content

"ESM Integration proposal for Wasm" support #4551

Open
@Tarnadas

Description

Clear and concise description of the problem

Hey! This is a feature request to add support for wasm-bindgen, a library to facilitate high-level interactions between Wasm modules and JavaScript for Rust.

wasm-bindgen has several output formats for generating Wasm <-> JS glue code, which most notably are web and bundler. I was hoping that the bundlertarger would be compatible with Vitejs, but unfortunately it's not. The output for the bundler target roughly looks like this:

// app.js
import * as wasm from "./app_bg.wasm";
export * from "./app_bg.js";
// app_bg.js
import * as wasm from './app_bg.wasm';
// ...
export function myWasmFunction() {
    wasm.myWasmFunction();
}

for this code:

async function main() {
  const wasmModule = await import('./app');
  wasmModule.myWasmFunction();

Suggested solution

There should be an alternative way to bundle Wasm files, which also supports dynamic import function. Probably add this as an option to the serve and build command or if possible auto detect.

Alternative

No response

Additional context

No response

Validations

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat: wasmp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions