You can make web browser games using Bevy. This chapter will help you with the things you need to know to do it. This page gives an overview of Bevy's Web support.
Your Bevy app will be compiled for WebAssembly (WASM), which allows it to be embedded in a web page and run inside the browser.
Performance will be limited, as WebAssembly is slower than native code and does not currently support multithreading.
Not all 3rd-party plugins are compatible. If you need extra unofficial plugins, you will have to check if they are compatible with WASM.
The same Bevy project, without any special code modifications, can be built for either web or desktop/native.
For development and testing, this can just be a minimal shim. It can be easily autogenerated.
When users want to play your game, their browser will need to download the files. Optimizing for size is important, so that your game can start faster and not waste data bandwidth.
dynamic_linking feature flag is not supported for
WASM builds. You cannot use it.
First, add WASM support to your Rust installation. Using Rustup:
rustup target install wasm32-unknown-unknown
The easiest and most automatic way to get started is the
It is great for testing during development.
cargo install wasm-server-runner
cargo to use it, in
.cargo/config.toml (in your project folder,
or globally in your user home folder):
[target.wasm32-unknown-unknown] runner = "wasm-server-runner"
Alternatively, you can also set the runner using an environment variable:
Now you can just run your game with:
cargo run --target wasm32-unknown-unknown
It will automatically run a minimal local webserver and open your game in your browser.
Here are some higher-level alternatives. These are feature-rich tools that can do more for you and automate much of your workflow, but are opinionated in how they work.
If you are a web developer and you want to make your own website where you embed your Bevy game, see here.