Change build_web.sh option from --fast to --optimize

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Alex Kazik 2022-07-07 19:02:12 +02:00 committed by Emil Ernerfeldt
parent c5a56f2082
commit 1ea0172f94
3 changed files with 14 additions and 16 deletions

View file

@ -62,15 +62,13 @@ You can compile your app to [WASM](https://en.wikipedia.org/wiki/WebAssembly) an
```sh
./setup_web.sh
./build_web.sh
./start_server.sh
open http://127.0.0.1:8080/
./build_web.sh --optimize --open
```
* `setup_web.sh` installs the tools required to build for web
* `build_web.sh` compiles your code to wasm and puts it in the `docs/` folder (see below)
* `start_server.sh` starts a local HTTP server so you can test before you publish
* Open http://127.0.0.1:8080/ in a web browser to view
* `build_web.sh` compiles your code to WASM and puts it in the `docs/` folder (see below) and `--open` opens the result in your default browser.
The finished web app is found in the `docs/` folder (this is so that you can easily share it with [GitHub Pages](https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site)). It consists of three files:

View file

@ -4,7 +4,7 @@ SET script_path=%~dp0
cd %script_path%
SET OPEN=0
SET FAST=0
SET OPTIMIZE=0
:do_while
IF (%1) == () GOTO end_while
@ -12,8 +12,8 @@ SET FAST=0
IF %1 == -h GOTO print_help
IF %1 == --help GOTO print_help
IF %1 == --fast (
SET FAST=1
IF %1 == --optimize (
SET OPTIMIZE=1
SHIFT
GOTO do_while
)
@ -56,7 +56,7 @@ echo Generating JS bindings for wasm...
SET TARGET_NAME=%CRATE_NAME_SNAKE_CASE%.wasm
wasm-bindgen "%TARGET%\wasm32-unknown-unknown\%BUILD%\%TARGET_NAME%" --out-dir "docs" --no-modules --no-typescript
IF %FAST% == 0 (
IF %OPTIMIZE% == 1 (
echo Optimizing wasm...
@REM to get wasm-opt: apt/brew/dnf install binaryen
@REM add -g to get debug symbols :
@ -70,8 +70,8 @@ IF %OPEN% == 1 start http://localhost:8080/index.html
GOTO end_program
:print_help
echo build_web.sh [--fast] [--open]
echo --fast: skip optimization step
echo build_web.sh [--optimize] [--open]
echo --optimize: optimize the generated WASM for performance
echo --open: open the result in a browser
GOTO end_program

View file

@ -7,19 +7,19 @@ script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
cd "$script_path"
OPEN=false
FAST=false
OPTIMIZE=false
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "build_web.sh [--fast] [--open]"
echo " --fast: skip optimization step"
echo "build_web.sh [--optimize] [--open]"
echo " --optimize: enable optimization step"
echo " --open: open the result in a browser"
exit 0
;;
--fast)
-O|--optimize)
shift
FAST=true
OPTIMIZE=true
;;
--open)
shift
@ -55,7 +55,7 @@ TARGET_NAME="${CRATE_NAME_SNAKE_CASE}.wasm"
WASM_PATH="${TARGET}/wasm32-unknown-unknown/${BUILD}/${TARGET_NAME}"
wasm-bindgen "${WASM_PATH}" --out-dir docs --no-modules --no-typescript
if [[ "${FAST}" == false ]]; then
if [[ "${OPTIMIZE}" == true ]]; then
echo "Optimizing wasm…"
# to get wasm-opt: apt/brew/dnf install binaryen
wasm-opt "docs/${CRATE_NAME}_bg.wasm" -O2 --fast-math -o "docs/${CRATE_NAME}_bg.wasm" # add -g to get debug symbols