Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
271 stars 14 forks source link

Wasm initialization missing using `npm run build` #54

Open finnbear opened 5 months ago

finnbear commented 5 months ago

I used this plugin to import the @dimforge/rapier3d physics engine, which uses WebAssembly internally. Everything works as expected when I run npm run dev. However, npm run build produces a dist/ directory with a .wasm file but no WebAssembly.instantiate*() of any kind in the .js file(s). As a result, an error is emitted the first time the nonexistent WebAssembly instance is accessed.

Here is a reproducible example: https://github.com/finnbear/vite-plugin-wasm-bug

image

Thanks for making this plugin!

crasite commented 4 months ago

Hello, have you found any workaround for this issues?

MaxBittker commented 3 months ago

Has anyone else found a solution for this?

MaxBittker commented 3 months ago

i worked around this with the compat build

finnbear commented 3 months ago

I used https://www.npmjs.com/package/@dimforge/rapier3d-compat as a workaround. The downside is it includes the Wasm binary as base64, which is less efficient for size and speed.