-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from trunk
to bevy run web
#312
base: main
Are you sure you want to change the base?
Conversation
Add a `bevy run` command which conveniently runs your Bevy app. It mostly wraps `cargo run`, but also provides a `web` sub command, which makes it a lot easier to target the browser. This option will compile your app for WASM, create JS bindings, add an `index.html` file if you don't provide one yourself and serves the build locally to open it in your browser. The default `index.html` file is mostly what we had in `bevy_quickstart`. This is the last part of #24. Closes #8. # Testing 1. Checkout the `bevy-run` branch. 2. Run `cargo install --path .` to install this version of the Bevy CLI. 3. Navigate to your Bevy app. 4. Run `bevy run web`. Note that your app must be compatible with WASM. If you have features or profiles enabled by default which are not compatible with WASM, you need to disable them. E.g. `bevy run --no-default-features web`. If you have a custom `index.html` configured for `trunk`, it might also not work out of the box. You can try removing the entire `web` folder to try the default setup. A good example project is of course `bevy_new_2d`, which you can test on this branch: <TheBevyFlock/bevy_new_2d#312>
# Objective Closes #196, unblocks <TheBevyFlock/bevy_new_2d#312>. With `wasm-opt`, we can further increase the performance and reduce the file size of the Wasm binary we use for web builds. This speeds ups the app both in-game and the loading times. # Solution As a simple first solution, we add a hard-coded size optimization pass in release mode. In future PRs, we can make this more configurable. To the user, we log the time the optimization took as well as the file size reduction as percentage. This is behind the `wasm-opt` feature flag (currently disabled by default), to give the user a way to turn this off and because this increases compile times of the CLI quite a bit.
# Objective Closes #68. Adds the `--bundle` argument to the `bevy build web` and `bevy run web` commands. This will pack all files needed for the web into a single folder. The location of the bundle will be `target/bevy_web/{profile}/{binary}`. This makes it a lot easier to deploy the app e.g. on itch.io or a generic web server. It also unblocks the switch from `trunk` to the Bevy CLI for the Bevy 2D template: <TheBevyFlock/bevy_new_2d#312>. # Solution - Add the `--bundle` option to the build and run web commands. - Create a new `WebBundle` enum, which can represent a linked or packed bundle: - A linked bundle is what we use by default, which is optimized for dev. It keeps e.g. the asset folder and WASM artifacts in their place to avoid duplication and copy operations. When running the app, the local web server will "link" together all the files and folders needed to run the app. - A packed bundle is a folder that contains all the necessary web artifacts. They will be copied in the directory. This option is most useful to deploy the web app.
Current status:
|
The release workflow can be triggered manually, but not from a PR, I believe. There are a few options:
|
The audio will be fixed by TheBevyFlock/bevy_cli#249. |
@benfrankel This should be ready now. For the CI I'm still uncertain if it already works as expected, but I'm fine with the options you proposed. |
# Objective The script for restarting the audio context for web apps didn't work. This resulted in the app not getting any audio. # Solution The fix is simple: The script for restarting the audio context needs to be called _before_ the app is loaded, I assume to ensure that the creation of the audio context is tracked correctly. # Testing You can test it on the current prototype of the [`bevy_new_2d` port](TheBevyFlock/bevy_new_2d#312). Compare `bevy run --no-default-features web --open` with the current `main` and this branch. This branch should have sound when you click the buttons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a first pass on the diff, and I have a few questions.
"label": "Run native release", | ||
"type": "cargo", | ||
"command": "run", | ||
"args": [ | ||
"--release", | ||
"--no-default-features" | ||
], | ||
"args": ["--release", "--no-default-features"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why we suggest that users use the Bevy CLI for native release while the .vscode/tasks.json
still uses cargo run
directly. Is VS Code special-cased to interpret the output of cargo
commands? Also, is there a benefit to bevy run
over cargo run
for native builds, or is it just for uniformity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, the native build and run is just a wrapper around cargo.
Consistency makes sense though, I will adjust that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the task type is set to cargo
, so there might actually be some special handling happening. That needs to be investigated further
For what it's worth I've been using these changes in a project and they've worked great for me. |
Putting this back to draft while we resolve the remaining regressions |
# Objective Partially related to #123. Removes one regression from <TheBevyFlock/bevy_new_2d#312>. When you currently run an app with `bevy run web`, the browser tab will just be called "Bey App". This is not very descriptive or nice, so it would be better if we could choose a better default value. # Solution - Adjust our bundling pipeline to allow pre-processing of the `index.html` in all cases - If not provided, add a `<title>` with the name of the binary - E.g. `bevy_new_2d` becomes "Bevy New 2d" As a follow-up to this PR we can also more easily apply the post-processing with the dev-only options for the dev server. # Testing 1. Install the CLI from this branch. 2. Run any Bevy project with `bevy run web`. It should show the name of the binary in the title. Try for example `bevy run --example=breakout web` in the bevy repository. 3. If you provide a custom `web/index.html` file and set a `<title>`, it should not be overwritten.
Objective
Closes #297.
This PR prepares the project to use the Bevy CLI, mainly the
bevy run
command.It simplifies especially running for the web target, which previously required use of
trunk
(and a bunch of additional configuration).Solution
web
andweb-release
profiles which use sensible defaults for web builds.--bundle
instead oftrunk
.trunk
.Note that this introduces a "regression" to the user that they now have to specify
--no-default-features
, which was automatically passed totrunk
.I created TheBevyFlock/bevy_cli#250 so we can do that in Bevy CLI as well.
Testing
gh pr checkout 312
(with the GitHub CLI)