isomorphic-rust/yew/build.sh

19 lines
870 B
Bash
Raw Permalink Normal View History

2018-08-25 18:18:42 -04:00
DIR="$(dirname $0)"
WASM_DIR="$DIR/target/wasm32-unknown-unknown"
2020-07-24 14:52:42 -04:00
NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
APP_DIR="$DIR/dist"
2018-08-25 18:18:42 -04:00
if [ ! -d "$APP_DIR" ]; then
mkdir "$APP_DIR"
fi
cp "$DIR/static/"* "$APP_DIR"
2018-08-25 18:18:42 -04:00
2020-07-24 14:52:42 -04:00
# Note: We'd normally prefer to use something like `wasm-pack` as a "production-ready" packager.
# However, when `wasm-pack` runs, it uses `wasm-bindgen` (which ultimately uses webpack 4.X) to
# build the Javascript bindings and thus still suffers from webpack/webpack#7918. Because we use
# the webpack CLI directly here, we benefit from changes in 5.X (specifically,
# the `asyncWebAssembly` experiment).
cargo build --target=wasm32-unknown-unknown && \
wasm-bindgen "$WASM_DIR/debug/$NAME.wasm" --out-dir "$APP_DIR" && \
"$DIR/node_modules/webpack-cli/bin/cli.js" "$APP_DIR/$NAME.js" -o "$APP_DIR/bundle.js"