Skip to content

Instantly share code, notes, and snippets.

@suhaotian
Last active March 14, 2025 12:04
Show Gist options
  • Save suhaotian/42155e2ea7ca54c0eb383e3738eff0ec to your computer and use it in GitHub Desktop.
Save suhaotian/42155e2ea7ca54c0eb383e3738eff0ec to your computer and use it in GitHub Desktop.
Get your lib bundle size with bun
#!/bin/bash
# Create a temporary file
TMP_FILE=$(mktemp)
# Build and save output to temp file
bun build dist/index.mjs --minify > "$TMP_FILE"
# Get original size
SIZE=$(cat "$TMP_FILE" | wc -c | awk '{comp=$1/1024; printf "%.2f", comp}')
echo "Size: $SIZE KB"
# Get gzipped size
GZIP_SIZE=$(cat "$TMP_FILE" | gzip -c | wc -c | awk '{comp=$1/1024; printf "%.2f", comp}')
echo "Gzip: $GZIP_SIZE KB"
# Clean up
rm "$TMP_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment