ln-832-bundle-optimizer

Reduces JS/TS bundle size via unused deps, tree-shaking, code splitting with keep/discard

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "ln-832-bundle-optimizer" with this command: npx skills add levnikolaevich/claude-code-skills/levnikolaevich-claude-code-skills-ln-832-bundle-optimizer

Paths: File paths (shared/, references/, ../ln-*) 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-832-bundle-optimizer

Type: L3 Worker Category: 8XX Optimization Parent: ln-830-code-modernization-coordinator

Reduces JavaScript/TypeScript bundle size. Metric: bundle size in bytes. Each optimization verified via build with keep/discard pattern. JS/TS projects only.


Overview

AspectDetails
InputJS/TS project (auto-detect from package.json)
OutputSmaller bundle, optimization report
ScopeJS/TS only (skip for other stacks)

Workflow

Phases: Pre-flight → Baseline → Analyze → Optimize Loop → Report


Phase 0: Pre-flight Checks

CheckRequiredAction if Missing
package.json existsYesBlock (not a JS/TS project)
Build command availableYesBlock (need build for size measurement)
dist/ or build/ outputYesRun build first to establish baseline
Git clean stateYesBlock (need clean baseline for revert)

MANDATORY READ: Load shared/references/ci_tool_detection.md — use Build section for build command detection.

Worktree & Branch Isolation

MANDATORY READ: Load shared/references/git_worktree_fallback.md — use ln-832 row.


Phase 1: Establish Baseline

Measure Current Bundle Size

1. Run build: npm run build (or detected build command)
2. Measure: total size of dist/ or build/ directory
3. Record: baseline_bytes, baseline_files
MetricHow
Total sizeSum of all files in output directory
Per-chunk sizesIndividual JS/CSS file sizes
Source map excludedDo not count .map files

Phase 2: Analyze Opportunities

Analysis Tools

CheckToolWhat It Finds
Unused dependenciesnpx depcheckPackages in package.json not imported anywhere
Bundle compositionnpx vite-bundle-visualizer or webpack-bundle-analyzerLarge dependencies, duplicates
Tree-shaking gapsManual scanimport * as instead of named imports
Code splittingRoute analysisLarge initial bundle, lazy-loadable routes

Optimization Categories

CategoryExampleTypical Savings
Remove unused depslodash installed but not imported10-50KB per dep
Named importsimport { debounce } from 'lodash-es' vs import _ from 'lodash'50-200KB
Lighter alternativesdate-fns instead of moment50-300KB
Dynamic importsReact.lazy(() => import('./HeavyComponent'))Reduce initial load
CSS optimizationPurge unused CSS, minify10-100KB

Phase 3: Optimize Loop (Keep/Discard)

Per-Optimization Cycle

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

Keep/Discard Decision

ConditionDecision
Build failsDISCARD
Bundle smallerKEEP (update baseline)
Bundle same or largerDISCARD

Optimization Order

OrderCategoryReason
1Remove unused depsSafest, immediate savings
2Named imports / tree-shakingMedium risk, good savings
3Lighter alternativesHigher risk (API changes)
4Dynamic imports / code splittingStructural change, test carefully
5CSS optimizationLowest priority

Phase 4: Report Results

Report Schema

FieldDescription
projectProject path
baseline_bytesOriginal bundle size
final_bytesFinal bundle size
reduction_bytesBytes saved
reduction_percentPercentage reduction
optimizations_appliedCount of kept optimizations
optimizations_discardedCount + reasons
details[]Per-optimization: category, description, bytes saved
deps_removed[]Unused dependencies removed

Configuration

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 Handling

ErrorCauseSolution
depcheck not availableNot installednpx depcheck (runs without install)
Build fails after removalDep used in dynamic import / configRevert, mark as false positive
No output directoryNon-standard build setupCheck package.json for output config
Not a JS/TS projectNo package.jsonSkip entirely with info message

References

  • shared/references/ci_tool_detection.md (build detection)

Definition of Done

  • JS/TS project confirmed (package.json present)
  • Baseline bundle size measured (build + measure dist/)
  • Unused deps identified via depcheck
  • Each optimization applied with keep/discard: build passes + smaller → keep
  • Compound: each kept optimization updates baseline for next
  • Report returned with baseline, final, reduction%, per-optimization details

Version: 1.0.0 Last Updated: 2026-03-08

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

ln-782-test-runner

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

ln-140-test-docs-creator

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

ln-110-project-docs-coordinator

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

ln-150-presentation-creator

No summary provided by upstream source.

Repository SourceNeeds Review