feat: build for web

This commit is contained in:
Christopher Willis-Ford 2022-10-14 17:38:49 -07:00
parent 6439bdda21
commit 395d3467f0
4 changed files with 51 additions and 1 deletions

View file

@ -6,8 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = { version = "0.8.1"}
[features]
# remember to disable bevy's "dynamic" feature for release builds
bevy = { version = "0.8.1", features = ["dynamic"]}
default = ["dynamic"]
dynamic = ["bevy/dynamic"]
# Enable minor optimization in dev builds
[profile.dev]
@ -16,3 +20,13 @@ opt-level = 1
# Enable more optimizations for dependencies, even in dev builds
[profile.dev.package."*"]
opt-level = 3
[profile.release]
lto = true
[profile.web-dev]
inherits = "dev"
[profile.web-release]
inherits = "release"
opt-level = 's'

14
build-for-web.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
set -e
# one-time setup:
# rustup target add wasm32-unknown-unknown
# cargo install -f wasm-bindgen-cli
# the "--no-default-features" setting is here to disable dynamic linking, which isn't supported for wasm
# see the [features] section of Cargo.toml for more detail
for PROFILE in web-dev web-release; do
cargo build --profile $PROFILE --no-default-features --target wasm32-unknown-unknown
wasm-bindgen --target web --out-dir ./target/web/$PROFILE ./target/wasm32-unknown-unknown/$PROFILE/scratch-bevy.wasm
done

11
index-dev.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>scratch-bevy</title>
</head>
<script type="module">
import init from './target/web/web-dev/scratch-bevy.js';
init();
</script>
</html>

11
index.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>scratch-bevy</title>
</head>
<script type="module">
import init from './target/web/web-release/scratch-bevy.js';
init();
</script>
</html>