Skip to content
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

Bevy run #120

Merged
merged 8 commits into from
Oct 3, 2024
Merged

Bevy run #120

merged 8 commits into from
Oct 3, 2024

Conversation

TimJentzsch
Copy link
Collaborator

@TimJentzsch TimJentzsch commented Sep 29, 2024

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

@TimJentzsch TimJentzsch added A-CLI Related to the main CLI and not a more specific subcommand C-Feature Make something new possible labels Sep 29, 2024
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I have a few nits, but feel free to merge this once you feel it is ready.

assets/web/index.html Show resolved Hide resolved
src/run/args.rs Outdated Show resolved Hide resolved
src/run/mod.rs Outdated Show resolved Hide resolved
src/run/mod.rs Outdated Show resolved Hide resolved
src/run/mod.rs Outdated Show resolved Hide resolved
src/run/args.rs Outdated Show resolved Hide resolved
src/run/mod.rs Outdated
wasm_bindgen::bundle(&package_name()?, args.profile())?;

let port = web_args.port;
let url = format!("http://127.0.0.1:{port}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had situations where https on localhost was necessary for development of a project. Do you think it would be nice to have the option here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, setting up HTTPS is not worth it for a development server such as this. The primary purpose of TLS is to secure communication across untrusted networks, but 127.0.0.1 is completely local, so there's no network to worry about. bevy run web is not meant for production. In those cases you build everything ahead of time and serve it with something like Nginx, which implements TLS already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to create a valid certificate for localhost to enable HTTPS?
I'd say that when we need it, we can create a follow-up issue to enable that functionality :)

Copy link

@BenjaminBrienen BenjaminBrienen Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, assuming openssl or the like is installed. We can leave it to the user to create their own self signed cert. It's a common step for web developers and is usually its own step outside of other tooling.

src/run/serve.rs Outdated Show resolved Hide resolved
@TimJentzsch TimJentzsch enabled auto-merge (squash) October 3, 2024 13:24
@TimJentzsch TimJentzsch merged commit 4c9c578 into main Oct 3, 2024
7 checks passed
@TimJentzsch TimJentzsch deleted the bevy-run branch October 3, 2024 13:26
@BD103 BD103 added A-Run Related to the bevy run command and removed A-CLI Related to the main CLI and not a more specific subcommand labels Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Run Related to the bevy run command C-Feature Make something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a command for running Bevy for web
3 participants