Created
September 9, 2025 11:55
-
-
Save mlafeldt/f079395b088ac4e45d58270bed8261ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Calculate bundle sizes for Cloudflare Pages worker modules. | |
| # Output similar to `wrangler pages dev`. | |
| set -euo pipefail | |
| cd "$(dirname "$0")/.." | |
| DIST_DIR="${1:-dist/_worker.js}" | |
| find "$DIST_DIR" -name "*.mjs" | grep -v ".map$" | \ | |
| xargs wc -c | \ | |
| sort -k1 -n | \ | |
| awk ' | |
| BEGIN { | |
| total_bytes = 0 | |
| module_count = 0 | |
| } | |
| { | |
| if (/total/) { | |
| total_bytes = $1 | |
| } else { | |
| printf "%8.1fK %s\n", $1/1024, $2 | |
| module_count++ | |
| } | |
| } | |
| END { | |
| printf "\033[1;33m%8.1fK\033[0m total (%d modules)\n", total_bytes/1024, module_count | |
| }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment