website/build-wasm.sh

36 lines
840 B
Bash
Raw Normal View History

2026-02-20 13:23:22 +00:00
#!/usr/bin/env bash
set -euo pipefail
PROFILE="${1:-release}"
if [ "$PROFILE" = "dev" ]; then
PROFILE_DIR="debug"
CARGO_FLAGS=""
else
PROFILE_DIR="release"
CARGO_FLAGS="--release"
fi
cargo build $CARGO_FLAGS --target wasm32-unknown-unknown -p app
mkdir -p static
2026-09-14 16:19:58 +00:00
# Drop stale bindgen / compression outputs from prior builds.
rm -f static/2dscene*
wasm-bindgen --out-name 2dscene \
2026-02-20 13:23:22 +00:00
--out-dir static \
--target web \
"target/wasm32-unknown-unknown/$PROFILE_DIR/app.wasm"
2026-09-14 16:19:58 +00:00
if [ "$PROFILE" != "dev" ]; then
wasm-opt -Oz --all-features -o static/2dscene_bg.wasm static/2dscene_bg.wasm
# Precompress assets Axum will negotiate via Accept-Encoding.
for f in static/2dscene_bg.wasm static/2dscene.js; do
gzip -9 -k -f "$f"
brotli -q 11 -f -k "$f"
done
fi
2026-02-20 13:23:22 +00:00
cp web/index.html static/