Use compressed WASM for even smaller webroot size
This commit is contained in:
13
Makefile
13
Makefile
@@ -17,19 +17,19 @@ SRCS := $(wildcard $(SRC_DIR)/**)
|
||||
|
||||
# "Standalone" version
|
||||
# (i.e., it includes an index.html so it can be placed on a server as-is)
|
||||
web-standalone: out/boids.js out/boids_bg.wasm out/index.html
|
||||
web-standalone: out/boids.js out/boids_bg.wasm.gz out/index.html
|
||||
|
||||
# "Bundle-able" version. The host site must provide it's own HTML page.
|
||||
web: out/boids.js out/boids_bg.wasm out/boids.html
|
||||
web: out/boids.js out/boids_bg.wasm.gz out/boids.html
|
||||
|
||||
tarball: boids_web_root.tar
|
||||
|
||||
tarball_standalone: boids_web_root_standalone.tar
|
||||
|
||||
boids_web_root.tar: out/boids.js out/boids_bg.wasm out/boids.html
|
||||
boids_web_root.tar: out/boids.js out/boids_bg.wasm.gz out/boids.html
|
||||
tar -caf $@ $^
|
||||
|
||||
boids_web_root_standalone.tar: out/boids.js out/boids_bg.wasm out/index.html
|
||||
boids_web_root_standalone.tar: out/boids.js out/boids_bg.wasm.gz out/index.html
|
||||
tar -caf $@ $^
|
||||
|
||||
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm: $(SRCS) Cargo.lock Cargo.toml
|
||||
@@ -40,8 +40,9 @@ out:
|
||||
|
||||
# Both the JS and WASM files are generated by the wasm-bindgen call, so both
|
||||
# get to be on the target half of this recipe.
|
||||
out/boids.js out/boids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
|
||||
out/boids.js out/boids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm | out
|
||||
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name boids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/another-boids-in-rust.wasm
|
||||
gzip -9 -f out/boids_bg.wasm
|
||||
|
||||
# Copies the index page to the output
|
||||
out/index.html: www/index.html
|
||||
@@ -68,5 +69,5 @@ full-clean: clean
|
||||
install: web
|
||||
install -dm0755 $(DESTDIR)
|
||||
install -m0644 out/boids.js $(DESTDIR)/
|
||||
install -m0644 out/boids_bg.wasm $(DESTDIR)/
|
||||
install -m0644 out/boids_bg.wasm.gz $(DESTDIR)/
|
||||
install -m0644 out/boids.html $(DESTDIR)/
|
||||
|
||||
@@ -112,7 +112,11 @@
|
||||
<script type="module">
|
||||
import init from './boids.js'
|
||||
|
||||
init().catch((error) => {
|
||||
let compressed = await fetch("./boids_bg.wasm.gz")
|
||||
let wasm_stream = compressed.body.pipeThrough(new DecompressionStream("gzip"))
|
||||
let blob = await new Response(wasm_stream).blob();
|
||||
|
||||
init(await blob.arrayBuffer()).catch((error) => {
|
||||
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user