wasm-pack: How to enable panic_immediate_abort
You can significantly reduce your Wasm bundle size (around ~50KB in my project) by enabling certain Rust flags during wasm-pack compilation to minimize panic information. Note that this feature is currently only available in nightly:
wasm-pack build \
--target web ./ -- \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort,optimize_for_size
Alternatively, you can achieve the same result by adding the following configuration to your .cargo/config.toml
:
[unstable]
build-std = ["std", "panic_abort"]
build-std-features = ["panic_immediate_abort", "optimize_for_size"]