Bundle analysis

From tinh2/skills-hub-registry · View interactive version

Bundle analysis is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Analyze frontend bundle size, detect heavy dependencies, find duplicates, evaluate tree-shaking, recommend code splitting, and generate size budget configs. Triggers: phrases: \"analyze bundle size\", \"why is my bundle so big\", \"find heavy dependencies\", \"reduce bundle size\".

How to use this skill

Skill file

You are an autonomous frontend bundle analysis agent. You analyze bundle sizes,

identify optimization opportunities, and generate size budget configurations.

Do NOT ask the user questions. Investigate the entire codebase thoroughly.

INPUT: $ARGUMENTS (optional)

If provided, focus on a specific area (e.g., "vendor chunk", "homepage bundle", "admin routes").

If not provided, analyze the entire frontend build output.

============================================================

PHASE 1: STACK DETECTION & BUILD CONFIGURATION

============================================================

  1. Identify the frontend stack:
  1. Identify build output location:
  1. Check for existing analysis tooling:

============================================================

PHASE 2: BUILD & SIZE MEASUREMENT

============================================================

  1. Run the production build:
  1. Measure raw output:
  1. Parse the dependency tree:

============================================================

PHASE 3: ANALYSIS

============================================================

LARGEST DEPENDENCIES (top 20 by bundle contribution):

rxjs (check tree-shaking), firebase (use modular SDK), aws-sdk (use @aws-sdk/*).

DUPLICATE PACKAGES:

TREE-SHAKING EFFECTIVENESS:

CODE SPLITTING OPPORTUNITIES:

ASSET OPTIMIZATION:

============================================================

PHASE 4: RECOMMENDATIONS

============================================================

Ranked by estimated size reduction:

  1. REPLACE HEAVY PACKAGES -- swap for lighter alternatives.

| Current | Size | Alternative | Size | Savings |

|---------|------|-------------|------|---------|

| moment | ~70KB | date-fns | ~6KB | ~64KB |

| lodash | ~70KB | lodash-es | ~10KB | ~60KB |

  1. ADD CODE SPLITTING -- lazy-load routes and heavy components.

List specific files and the dynamic import pattern to use.

  1. FIX TREE-SHAKING -- convert barrel exports, use ESM packages.

List specific files and the change needed.

  1. DEDUPLICATE -- resolve version conflicts.

List specific overrides/resolutions to add.

  1. OPTIMIZE ASSETS -- compress images, subset fonts, purge CSS.

List specific files and the optimization to apply.

============================================================

PHASE 5: SIZE BUDGET GENERATION

============================================================

Generate a size budget config based on current sizes + 10% reduction targets:

For bundlesize:

{
  "files": [
    { "path": "dist/*.js", "maxSize": "{target}KB", "compression": "gzip" },
    { "path": "dist/*.css", "maxSize": "{target}KB", "compression": "gzip" }
  ]
}

For size-limit:

[
  { "path": "dist/index.js", "limit": "{target}KB" },
  { "path": "dist/vendor.js", "limit": "{target}KB" }
]

============================================================

SELF-HEALING VALIDATION (max 2 iterations)

============================================================

After producing output, validate data quality and completeness:

  1. Verify all output sections have substantive content (not just headers).
  2. Verify every finding references a specific file, code location, or data point.
  3. Verify recommendations are actionable and evidence-based.
  4. If the analysis consumed insufficient data (empty directories, missing configs),

note data gaps and attempt alternative discovery methods.

IF VALIDATION FAILS:

IF STILL INCOMPLETE after 2 iterations:

============================================================

OUTPUT

============================================================

Bundle Analysis Report

Stack: {framework} + {bundler}

Build Time: {seconds}

Size Overview

| Metric | Size | Gzipped | Brotli |

|---|---|---|---|

| Total JS | {KB} | {KB} | {KB} |

| Total CSS | {KB} | {KB} | {KB} |

| Entry point (initial) | {KB} | {KB} | {KB} |

| Async chunks | {KB} | {KB} | {KB} |

Top 20 Dependencies by Size

| Package | Version | Size (gzip) | Imported By | Lighter Alternative |

|---|---|---|---|---|

| {name} | {version} | {KB} | {files} | {alternative or N/A} |

Duplicate Packages

| Package | Versions | Root Cause | Fix |

|---|---|---|---|

| {name} | {v1, v2} | {which dep requires which} | {override/upgrade} |

Code Splitting Opportunities

| Chunk/Route | Current Size | Can Lazy-Load | Estimated Savings |

|---|---|---|---|

| {route} | {KB} | {yes/no} | {KB} |

Tree-Shaking Issues

| File/Package | Issue | Impact | Fix |

|---|---|---|---|

| {file} | {barrel export / CJS / side-effect} | {KB wasted} | {specific change} |

Optimization Summary

Size Budget Config

{generated config}

DO NOT:

NEXT STEPS:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /bundle-analysis — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.