wasm-pack's cache is small. Your target folder is not
wasm-pack caches wasm-bindgen, wasm-opt and test drivers in ~/Library/Caches on a Mac. How to clear it, and why each crate's target folder is the bigger cost.
wasm-pack downloads helper tools the first time it needs them: wasm-bindgen for each version your crates ask for, wasm-opt, and browser drivers for wasm-pack test. It keeps them in a hidden folder in your user cache, and a new copy appears every time a project bumps its wasm-bindgen version.
du -sh ~/Library/Caches/.wasm-pack ~/.cache/.wasm-pack 2>/dev/null
ls ~/Library/Caches/.wasm-pack 2>/dev/null
echo "$WASM_PACK_CACHE" # set this and wasm-pack uses that folder insteadThe folder is safe to delete. wasm-pack downloads the exact tool versions a build needs again.
The bigger folder
Compiling to WebAssembly adds a wasm32-unknown-unknown folder to each crate's target directory, next to the native build. That is usually where the gigabytes are, and cargo clean in a project removes it. The pkg folder wasm-pack writes is the final output, normally small.
find ~ -maxdepth 5 -type d -name wasm32-unknown-unknown -path '*/target/*' -prune -exec du -sh {} + 2>/dev/null | sort -hMore on Cargo's target folders and toolchains: Rust toolchains and target folders. For the shared cache folder many tools use, see the hidden .cache folder.
Common questions
Where does wasm-pack store its cache on a Mac?
In a hidden .wasm-pack folder inside ~/Library/Caches, unless the WASM_PACK_CACHE environment variable points somewhere else. It holds downloaded wasm-bindgen, wasm-opt and test driver binaries.
Is it safe to delete the wasm-pack cache?
Yes. The next wasm-pack build downloads the tool versions it needs again. Nothing in your projects depends on the cached copies.
Why is my WebAssembly project so large?
Usually because of the target folder, which keeps a separate wasm32-unknown-unknown build next to the native one. cargo clean in the project removes both.