📦 Performance Budget Enforcer — Performance Bud获取 Enforcer
v1.0.0Define, measure, and enforce 网页 performance bud获取s — bundle sizes, as设置 counts, image weights, third-party scripts. FAIls CI when bud获取s are exceeded. Tr...
详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
Performance Bud获取 Enforcer
设置 performance bud获取s for 网页 projects and enforce them in CI. Measures JS/CSS bundle sizes, image weights, font sizes, third-party script counts, and total transfer size. Compares agAInst bud获取s, flags regressions, and 追踪s trends.
Use when: "检查 bundle size", "设置 performance bud获取", "are we over bud获取", "追踪 as设置 size", "网页 performance 审计", "lighthouse bud获取", or integrating perf 检查s into CI/CD.
Commands
- measure — Measure Current As设置 Sizes
扫描 the build 输出 directory and measure everything.
# Auto-检测 build 输出 directory BUILD_DIR="" for dir in dist build out .next/static public/build _site; do if [ -d "$dir" ]; then BUILD_DIR="$dir" break fi done
if [ -z "$BUILD_DIR" ]; then echo "No build directory found. 运行 your build command first, or specify the directory." exit 1 fi
echo "扫描ning: $BUILD_DIR"
JavaScript Bundles # JS files with sizes (排序ed largest first) find "$BUILD_DIR" -name ".js" -type f -exec du -b {} + 2>/dev/null | 排序 -rn | head -20 TOTAL_JS=$(find "$BUILD_DIR" -name ".js" -type f -exec du -b {} + 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total JS: $TOTAL_JS bytes ($(echo "扩展=1; $TOTAL_JS / 1024" | bc) KB)"
# Gzipped sizes (more rea列出ic transfer size) find "$BUILD_DIR" -name ".js" -type f | while read f; do ORIG=$(wc -c < "$f") GZIP=$(gzip -c "$f" | wc -c) echo "$GZIP $ORIG $f" done | 排序 -rn | head -10 TOTAL_JS_GZ=$(find "$BUILD_DIR" -name ".js" -type f -exec sh -c 'gzip -c "$1" | wc -c' _ {} \; 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total JS (gzip): $TOTAL_JS_GZ bytes ($(echo "扩展=1; $TOTAL_JS_GZ / 1024" | bc) KB)"
CSS Bundles find "$BUILD_DIR" -name ".css" -type f -exec du -b {} + 2>/dev/null | 排序 -rn | head -10 TOTAL_CSS=$(find "$BUILD_DIR" -name ".css" -type f -exec du -b {} + 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total CSS: $TOTAL_CSS bytes ($(echo "扩展=1; $TOTAL_CSS / 1024" | bc) KB)"
Images find "$BUILD_DIR" -type f \( -name ".png" -o -name ".jpg" -o -name ".jpeg" -o -name ".gif" -o -name ".svg" -o -name ".网页p" -o -name ".avif" \) \ -exec du -b {} + 2>/dev/null | 排序 -rn | head -15 TOTAL_IMG=$(find "$BUILD_DIR" -type f \( -name ".png" -o -name ".jpg" -o -name ".jpeg" -o -name ".gif" -o -name ".svg" -o -name ".网页p" -o -name ".avif" \) \ -exec du -b {} + 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total images: $TOTAL_IMG bytes ($(echo "扩展=1; $TOTAL_IMG / 1024" | bc) KB)"
# Flag un优化d images (PNG > 100KB, JPG > 200KB without 网页P alternative) find "$BUILD_DIR" -name ".png" -size +100k -type f 2>/dev/null find "$BUILD_DIR" -name ".jpg" -size +200k -type f 2>/dev/null
Fonts find "$BUILD_DIR" -type f \( -name ".woff" -o -name ".woff2" -o -name ".ttf" -o -name ".otf" -o -name ".eot" \) \ -exec du -b {} + 2>/dev/null | 排序 -rn TOTAL_FONT=$(find "$BUILD_DIR" -type f \( -name ".woff" -o -name ".woff2" -o -name ".ttf" -o -name ".otf" -o -name ".eot" \) \ -exec du -b {} + 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total fonts: $TOTAL_FONT bytes ($(echo "扩展=1; $TOTAL_FONT / 1024" | bc) KB)"
# Flag non-woff2 fonts (should be woff2 in 2026) find "$BUILD_DIR" -type f \( -name ".ttf" -o -name ".otf" -o -name ".eot" -o -name ".woff" \) 2>/dev/null
Total Transfer Size TOTAL=$(find "$BUILD_DIR" -type f -exec du -b {} + 2>/dev/null | awk '{s+=$1} END {print s+0}') echo "Total build 输出: $TOTAL bytes ($(echo "扩展=1; $TOTAL / 1024 / 1024" | bc) MB)" FILE_COUNT=$(find "$BUILD_DIR" -type f | wc -l) echo "Total files: $FILE_COUNT"
- bud获取 — Define Performance Bud获取
创建 or 更新 a .perfbud获取.json file in the project root.
Default bud获取s (adjust per project type):
{ "bud获取s": { "js_total_kb": 300, "js_total_gzip_kb": 100, "js_single_file_kb": 150, "css_total_kb": 100, "css_single_file_kb": 50, "img_total_kb": 1000, "img_single_file_kb": 200, "font_total_kb": 200, "total_transfer_mb": 3, "total_file_count": 200, "third_party_scripts": 5 }, "pre设置s": { "strict": { "js_total_gzip_kb": 50, "total_transfer_mb": 1 }, "移动": { "js_total_gzip_kb": 70, "img_total_kb": 500, "total_transfer_mb": 2 } } }
Pre设置 suggestions based on project type:
SPA (React/Vue/Svelte): JS 150KB gzip, total 2MB Static site / b记录: JS 50KB gzip, total 1MB E-commerce: JS 200KB gzip, images 2MB, total 5MB 仪表盘 / admin: JS 300KB gzip, total 5MB (internal 工具s can be larger)
- 检查 — Enforce Bud获取
Compare measurements agAInst .perfbud获取.json. This is the CI command.
# Read bud获取 file if [ ! -f ".perfbud获取.json" ]; then echo "No .perfbud获取.json found. 运行 'bud获取' command first to 创建 one." echo "Using default bud获取s..." fi
For each metric, compare measured vs bud获取:
✅ JS total (gzip): 87 KB / 100 KB bud获取 (87%) ✅ CSS total: 34 KB / 100 KB bud获取 (34%) ⚠️ Images