Warning
DRAFT. Once reviewed and approved by the working group, it can be published as a Discussion on the Bevy repo to invite a broader discussion.
In this initiative, we aim to improve the process of developing web applications with Bevy.
It's part of the Bevy CLI working group, join us on Discord if you wish to participate!
Note
The Bevy CLI is about more than just the web functionality (e.g. also linting Bevy apps).
However, this design document is scoped to just the web aspects.
Developing Bevy apps for the browser has long been a second class citizen.
This is problematic, because many users' first contact with Bevy is in its web form – through the Bevy game jam.
One goal of the Bevy game jam is to pull in new users and encourage them to get started with Bevy. But through the nature of game jams, web apps have a higher chance of being played and rated. Hence, having a good web dev experience can make a big difference in onboarding and user success.
Let's compare how you can run the app on native vs. in the browser:
Setup:
Dev cycle:
cargo run
, to build and run the app.Setup:
rustup target add wasm32-unknown-unknown
, to be able to compile to Wasm.cargo install wasm-bindgen-cli
, which can create JS bindings for the Wasm executable.index.html
file, which is the entrypoint for the web application.Dev cycle:
cargo build --target wasm32-unknown-unknown
to build the app for Wasm.wasm-bindgen
(with sensible arguments) to create JS bindings for the Wasm executable.index.html
, Wasm, JS and asset files into a folder.trunk
can simplify this process.Developing for the browser is more challenging than native because of the numerous steps required. This leads to developers writing custom scripts to automate the process, fracturing the community, and the increased number of steps expands the margin for error.
And with all of this work, you won't even get a good product: Wasm binaries have quite different needs than native builds. File size, for example, is often more important than speed because it determines the loading times of your app. Cargo's --release
profile doesn't prioritize this by default, however, hurting player experience on the web. You can amend this by configuring custom profiles, but you must remember to use them for all your web builds.
The Bevy CLI abstracts over the difficulties of building games for Wasm by reducing the above steps into a single command, and providing sane defaults that developers rarely need to override.
So now that we want to develop a Bevy CLI and use it to improve the web dev experience, we need to set some general design guidelines to streamline this process.
cargo
CLI. They shouldn't have to learn many new commands to be able to use the Bevy CLI. We should reuse as many command arguments as possible to make it easy to get started.cargo
directly.Here is an overview of the functionality we want to include in the first user-facing release of the Bevy CLI:
index.html
should be provided automatically if the user didn't set one up.Beyond the MVP, we can already envision other functionality that would benefit users, but is either not critical to get working or requires a lot more implementation work:
cargo watch
for native builds (which we could also integrate into the CLI). The browser tab should automatically refresh once the rebuild is complete. Re-creating the state in the Bevy app (i.e., hot reloading) would also be cool, but not necessary for the first iteration of this feature.canvas
size. Many of these adjustments will likely need changes in Bevy itself instead of the CLI.With the Bevy CLI prototype, we have already implemented most of the MVP functionality.
You can try it out by running cargo install --git https://github.com/TheBevyFlock/bevy_cli --locked bevy_cli
.
Play around with the bevy build web
and bevy run web
commands. For example, use bevy run --example breakout web
inside the Bevy repository.
The bevy build
and bevy run
commands offer almost the same arguments as their cargo
counterparts. Use bevy run web --help
to find out about additional arguments available for web builds.
Note that this is still a prototype, which means that some things might not yet work as expected. At the same time, it also means that nothing is set in stone yet – we will make adjustments based on the feedback we receive.
Of course, you can also contribute directly to the project!