You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Reacted by Huseyn Guliyev, Virgiel, Ai Yanbo, Johannes Schickling, Alexander Nanberg, Isaak Eriksson, stefnotch, Taylor Denouden, Sean Colsen, Jonathan and 11 more
This might be a similar issue to #3847. One thing is clear not all wasm files are importable by vite as described in the docs. I had to struggle a lot before managing to get rust compiled wasm files to work with vite. Will be great to at least produce some guidance on expected wasm format.
This might be a similar issue to #3847. One thing is clear not all wasm files are importable by vite as described in the docs. I had to struggle a lot before managing to get rust compiled wasm files to work with vite. Will be great to at least produce some guidance on expected wasm format.
I agree. I tried using a wasm-markdown packages for a while, had headaches for days trying to solve it, but in the end i gave up when I could not get it to work. Some wasm packages work fine, some don't, I didn't know there are different wasm formats.
The init function is generated by wasm-pack automatically when using the web target (more info). It loads the actual wasm file so you have to call it before you can use your wasm functions.
I changed the wasm plugin to match the behavior of Webpack 5's asyncWebAssembly and WebAssembly's esm-integration proposal.
Only simple default/named imports/exports of functions and memory object are supported at this time (I didn't test one .wasm file with other type of imports/exports but in theory it should work.). I tested my module syntect-js and it's working as expected (just like in Webpack 5).
Reacted by Julian Jarecki, I'm Lun and Brandon Tsang
Reacted by Arno Schlipf, Huseyn Guliyev, Yehyoung Kang, Jiawen Geng, Ricardo M. Vilchis, Honwhy Wang, Dennis Lonoshchuk, Nicolò Maria Semprini and Brandon Tsang
Reacted by Frank Hampus Weslien, Frédéric Llorca, Christophe Petitjean, Dennis Lonoshchuk, Brandon Tsang, Andrew Blair, Martin Renold and Louis
Activity
husayt commentedon Aug 20, 2021
This might be a similar issue to #3847. One thing is clear not all wasm files are importable by vite as described in the docs. I had to struggle a lot before managing to get rust compiled wasm files to work with vite. Will be great to at least produce some guidance on expected wasm format.
Fanna1119 commentedon Nov 5, 2021
I agree. I tried using a wasm-markdown packages for a while, had headaches for days trying to solve it, but in the end i gave up when I could not get it to work. Some wasm packages work fine, some don't, I didn't know there are different wasm formats.
arnoson commentedon Nov 30, 2021
Just a quick info, if somebody else is looking here for a solution to load wasm modules generated by wasm pack (with target
web, notbundler):This didn't work for me
But importing the url with vite works:
But getting the
bundlertarget to work with vite would be even better :)Fanna1119 commentedon Dec 1, 2021
what exactly does the
initrefer to?arnoson commentedon Dec 1, 2021
The
initfunction is generated by wasm-pack automatically when using thewebtarget (more info). It loads the actual wasm file so you have to call it before you can use your wasm functions.Menci commentedon Jan 16, 2022
I changed the wasm plugin to match the behavior of Webpack 5's
asyncWebAssemblyand WebAssembly's esm-integration proposal.Only simple default/named imports/exports of functions and memory object are supported at this time (I didn't test one .wasm file with other type of imports/exports but in theory it should work.). I tested my module syntect-js and it's working as expected (just like in Webpack 5).
My patch is here: Menci@1a19965
It generates the following JS code for
.wasm?urlimports:Menci commentedon Mar 4, 2022
I have published my solution as a plugin: https://github.com/Menci/vite-plugin-wasm. This works for both modern and legacy browsers.
sapphi-red commentedon Sep 6, 2024
ESM Integration proposal for Wasm is now stage 3 and the related PR in HTML spec (whatwg/html#10380) has been merged.
I think we can have it builtin.
Although, I guess it will require top-level-await support and might encounter a bug in rollup (rollup/rollup#4708).
[-]Make WebAssembly bundling work with wasm-bindgen[/-][+]"ESM Integration proposal for Wasm" support[/+]