Compress the WASM file for even more space savings
This commit is contained in:
13
Makefile
13
Makefile
@@ -15,20 +15,20 @@ SRCS := $(wildcard $(SRC_DIR)/**)
|
||||
.PHONY: clean full-clean tarball tarball-standalone web web-standalone
|
||||
|
||||
# "Standalone" version. It includes an index.html to serve as-is
|
||||
web-standalone: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
||||
web-standalone: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html
|
||||
|
||||
# "Bundle-able" version. It has a page, but no index.html. Consumers are
|
||||
# expected to provide their own index.html and link to this page.
|
||||
web: out/asteroids.js out/asteroids_bg.wasm out/asteroids.html
|
||||
web: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html
|
||||
|
||||
tarball: asteroids_web_root.tar
|
||||
|
||||
tarball_standalone: asteroids_web_root_standalone.tar
|
||||
|
||||
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm out/asteroids.html
|
||||
asteroids_web_root.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/asteroids.html
|
||||
tar -caf $@ $^
|
||||
|
||||
asteroids_web_root_standalone.tar: out/asteroids.js out/asteroids_bg.wasm out/index.html
|
||||
asteroids_web_root_standalone.tar: out/asteroids.js out/asteroids_bg.wasm.gz out/index.html
|
||||
tar -caf $@ $^
|
||||
|
||||
target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm: $(SRCS) Cargo.lock Cargo.toml
|
||||
@@ -39,8 +39,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/asteroids.js out/asteroids_bg.wasm &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out
|
||||
out/asteroids.js out/asteroids_bg.wasm.gz &: target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm | out
|
||||
wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name asteroids target/$(CARGO_TARGET)/$(CARGO_PROFILE)/asteroids.wasm
|
||||
gzip -9 -f out/asteroids_bg.wasm
|
||||
|
||||
# Copies the index page to the output dir.
|
||||
out/index.html: www/index.html
|
||||
@@ -67,5 +68,5 @@ full-clean: clean
|
||||
install: web
|
||||
install -dm0755 $(DESTDIR)
|
||||
install -m0644 out/asteroids.js $(DESTDIR)/
|
||||
install -m0644 out/asteroids_bg.wasm $(DESTDIR)/
|
||||
install -m0644 out/asteroids_bg.wasm.gz $(DESTDIR)/
|
||||
install -m0644 out/asteroids.html $(DESTDIR)/
|
||||
|
||||
@@ -98,7 +98,11 @@
|
||||
<script type="module">
|
||||
import init from './asteroids.js'
|
||||
|
||||
init().catch((error) => {
|
||||
let compressed = await fetch("./asteroids_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