秋逸

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"]

References

wasm-pack: How to enable panic_immediate_abort
: 杨秋逸
https://yangqiuyi.com/blog/开发/wasm-pack-how-to-enable-panic_immediate_abort/
© 2025 杨秋逸 . All rights reserved.