From f96f1131471ca2b3caa0f4ea7780f5b80b1d5dd0 Mon Sep 17 00:00:00 2001 From: TimJentzsch Date: Sun, 29 Dec 2024 19:42:55 +0100 Subject: [PATCH] Add `--bundle` option to `web` commands (#195) # 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: . # 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. --- Cargo.lock | 7 ++ Cargo.toml | 3 + assets/web/index.html | 1 + src/build/args.rs | 13 +++- src/build/mod.rs | 13 +++- src/run/args.rs | 4 + src/run/mod.rs | 16 +++- src/run/serve.rs | 91 ++++++++++------------ src/web/bundle.rs | 170 ++++++++++++++++++++++++++++++++++++++++++ src/web/mod.rs | 3 + 10 files changed, 265 insertions(+), 56 deletions(-) create mode 100644 src/web/bundle.rs diff --git a/Cargo.lock b/Cargo.lock index 6f040a6c..cbda72ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -492,6 +492,7 @@ dependencies = [ "cargo-generate", "clap", "dialoguer", + "fs_extra", "regex", "reqwest", "semver", @@ -1612,6 +1613,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures-channel" version = "0.3.31" diff --git a/Cargo.toml b/Cargo.toml index 8d569518..737a9670 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,5 +48,8 @@ actix-web = "4.9.0" # Opening the app in the browser webbrowser = "1.0.2" +# Copying directories +fs_extra = "1.3.0" + # Optimizing Wasm binaries wasm-opt = { version = "0.116.1", optional = true } diff --git a/assets/web/index.html b/assets/web/index.html index 476d79a3..b7de1fc0 100644 --- a/assets/web/index.html +++ b/assets/web/index.html @@ -65,6 +65,7 @@