Loading...
Loading...
Reduces JS/TS bundle size via unused deps, tree-shaking, code splitting with keep/discard
npx skill4agent add levnikolaevich/claude-code-skills ln-832-bundle-optimizerPaths: File paths (,shared/,references/) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.../ln-*
| Aspect | Details |
|---|---|
| Input | JS/TS project (auto-detect from package.json) |
| Output | Smaller bundle, optimization report |
| Scope | JS/TS only (skip for other stacks) |
| Check | Required | Action if Missing |
|---|---|---|
| package.json exists | Yes | Block (not a JS/TS project) |
| Build command available | Yes | Block (need build for size measurement) |
| dist/ or build/ output | Yes | Run build first to establish baseline |
| Git clean state | Yes | Block (need clean baseline for revert) |
shared/references/ci_tool_detection.mdshared/references/git_worktree_fallback.md1. Run build: npm run build (or detected build command)
2. Measure: total size of dist/ or build/ directory
3. Record: baseline_bytes, baseline_files| Metric | How |
|---|---|
| Total size | Sum of all files in output directory |
| Per-chunk sizes | Individual JS/CSS file sizes |
| Source map excluded | Do not count .map files |
| Check | Tool | What It Finds |
|---|---|---|
| Unused dependencies | | Packages in package.json not imported anywhere |
| Bundle composition | | Large dependencies, duplicates |
| Tree-shaking gaps | Manual scan | |
| Code splitting | Route analysis | Large initial bundle, lazy-loadable routes |
| Category | Example | Typical Savings |
|---|---|---|
| Remove unused deps | | 10-50KB per dep |
| Named imports | | 50-200KB |
| Lighter alternatives | | 50-300KB |
| Dynamic imports | | Reduce initial load |
| CSS optimization | Purge unused CSS, minify | 10-100KB |
FOR each optimization (O1..ON):
1. APPLY: Make change (remove dep, rewrite import, add lazy load)
2. BUILD: Run build command
IF build FAILS → DISCARD (revert) → next optimization
3. MEASURE: New bundle size
4. COMPARE:
IF new_bytes < baseline_bytes → KEEP (new baseline = new_bytes)
IF new_bytes >= baseline_bytes → DISCARD (revert, no improvement)
5. LOG: Record result| Condition | Decision |
|---|---|
| Build fails | DISCARD |
| Bundle smaller | KEEP (update baseline) |
| Bundle same or larger | DISCARD |
| Order | Category | Reason |
|---|---|---|
| 1 | Remove unused deps | Safest, immediate savings |
| 2 | Named imports / tree-shaking | Medium risk, good savings |
| 3 | Lighter alternatives | Higher risk (API changes) |
| 4 | Dynamic imports / code splitting | Structural change, test carefully |
| 5 | CSS optimization | Lowest priority |
| Field | Description |
|---|---|
| project | Project path |
| baseline_bytes | Original bundle size |
| final_bytes | Final bundle size |
| reduction_bytes | Bytes saved |
| reduction_percent | Percentage reduction |
| optimizations_applied | Count of kept optimizations |
| optimizations_discarded | Count + reasons |
| details[] | Per-optimization: category, description, bytes saved |
| deps_removed[] | Unused dependencies removed |
Options:
# Build
build_command: "" # Auto-detect from ci_tool_detection.md
output_dir: "" # Auto-detect: dist/ or build/
# Analysis
run_depcheck: true
run_bundle_analyzer: false # Opens browser, skip in CI
# Optimization scope
remove_unused_deps: true
fix_tree_shaking: true
suggest_alternatives: true
add_code_splitting: false # Structural change, opt-in
# Verification
run_build: true| Error | Cause | Solution |
|---|---|---|
| depcheck not available | Not installed | |
| Build fails after removal | Dep used in dynamic import / config | Revert, mark as false positive |
| No output directory | Non-standard build setup | Check package.json for output config |
| Not a JS/TS project | No package.json | Skip entirely with info message |
shared/references/ci_tool_detection.md