tl;dr: WebAssembly is supported as of π Hanabi 0.13.
The WebAssembly target (a.k.a. "wasm"; cargo's --target wasm32-unknown-unknown
) is supported.
However, because π Hanabi makes heavy usage of compute shaders,
like several other advanced Bevy features,
it requires using the WebGPU render backend of Bevy instead of the WebGL2 one.
This has limiting implications which app authors should understand before using π Hanabi.
In particular, as of 2024:
- Chrome and Edge only enable WebGPU from version 113 (April 2023);
- Firefox still disables WebGPU by default, and either requires a nightly build or the user changing its internal flags.
Mozilla has a Browser compatibility table to understand where and how WebGPU is available on web browsers.
For more information about WebAssembly support, see also:
- Bevy's own explanations on how to run its examples on WebGL2 and WebGPU.
- The WebAssembly section of the Unofficial Bevy Cheat Book.
The serde
feature,
which allows deriving the Serialize
and Deserialize
traits on asset-related types,
is not compatible with the wasm
target.
This is due to the use of the typetag
dependency to handle trait objects,
which itself is not available for wasm
.
To disable the serde
feature,
simply disable default features and explicitly list the features you need:
cargo b --target wasm32-unknown-unknown --no-default-features --features="2d 3d"
The simplest way is to make use of the http-server
NPM package,
combined with npx
from NodeJS to execute it.
- Install NodeJS
- Copy the
assets/
folder intoexamples\wasm\
; this is a quick and simple workaround for the HTTP server to find the assets - Execute
npx http-server examples\wasm
, which will run thehttp-server
package without having to install it - Open a compatible browser (e.g. Chrome or Edge) at
http://127.0.0.1:8080/
(or the addresshttp-server
will print in the console)
See also the WebAssembly section of the Unofficial Bevy Cheat Book for more tools and ways to build and run Bevy apps on Web.