skills-catalog/ln-832-bundle-optimizer/SKILL.md
Reduces JS/TS bundle size via tree-shaking, code splitting, and unused dependency removal. Use when optimizing frontend bundle size.
npx skillsauth add levnikolaevich/claude-code-skills ln-832-bundle-optimizerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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. Ifshared/is missing, fetch files via WebFetch fromhttps://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}.
Type: L3 Worker Category: 8XX Optimization
Reduces JavaScript or TypeScript bundle size using keep/discard verification. JS/TS projects only.
| Aspect | Details | |--------|---------| | Input | JS/TS project path plus optional optimization scope | | Output | Smaller bundle plus a machine-readable modernization summary | | Scope | JS/TS only |
Phases: Pre-flight -> Baseline -> Analyze -> Optimize Loop -> Report
| Check | Required | Action if Missing |
|-------|----------|-------------------|
| package.json exists | Yes | Block optimization |
| Build command available | Yes | Block optimization |
| Output directory (dist/ or build/) detectable | Yes | Build once to establish baseline |
| Workspace baseline safe | Yes | In managed runs coordinator already prepared it; in standalone runs protect rollback locally |
MANDATORY READ: Load shared/references/ci_tool_detection.md for build detection.
MANDATORY READ: Load shared/references/mcp_tool_preferences.md and shared/references/mcp_integration_patterns.md
Use hex-graph first when hotspots or clone groups materially improve optimization targeting. Use hex-line first for local code and config reads when available. If MCP is unavailable, unsupported, or not indexed, continue with built-in Read/Grep/Glob/Bash and state the fallback in the summary.
Managed runs receive deterministic runId and exact summaryArtifactPath from ln-830.
Standalone runs remain supported; if runtime arguments are omitted, generate a standalone run-scoped artifact before returning.
1. Run the detected build command.
2. Measure total size of the output directory.
3. Record baseline bytes and per-chunk sizes.
| Metric | How |
|--------|-----|
| Total size | Sum all bundle output files except source maps |
| Per-chunk sizes | Measure individual JS and CSS files |
| Source map handling | Exclude .map files |
| Check | Tool | What It Finds |
|-------|------|---------------|
| Unused dependencies | depcheck or equivalent | Packages not imported anywhere |
| Bundle composition | Bundle analyzer | Large dependencies or duplicates |
| Tree-shaking gaps | Manual scan | Namespace imports or heavy entrypoints |
| Code splitting gaps | Route analysis | Lazy-load candidates |
Optimization categories:
| Category | Example | Typical Savings |
|----------|---------|----------------|
| Remove unused deps | dead dependencies | 10-50KB per package |
| Named imports | lodash-es named imports | 50-200KB |
| Lighter alternatives | replace heavy date or utility libs | 50-300KB |
| Dynamic imports | lazy-load heavy components | lower initial bundle |
| CSS optimization | remove unused CSS, minify | 10-100KB |
Per-optimization cycle:
FOR each optimization:
1. APPLY the change
2. BUILD
IF build fails -> DISCARD and revert
3. MEASURE new bundle size
4. KEEP only if the bundle is smaller than the current baseline
5. LOG the result
Stop conditions:
| Condition | Action | |-----------|--------| | All optimizations processed | Stop and report | | 3 consecutive discards | Stop for plateau | | Build infrastructure breaks | Revert to last keep and stop | | Bundle already below target | Stop and report |
Optimization order:
| 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 plus reasons |
| deps_removed[] | Dependencies removed |
| details[] | Per-optimization savings |
| artifact_path | Durable worker report path, if written |
Options:
build_command: "" # Auto-detect
output_dir: "" # Auto-detect
run_depcheck: true
run_bundle_analyzer: false
remove_unused_deps: true
fix_tree_shaking: true
replace_heavy_libraries: true
enable_code_splitting: true
| Error | Cause | Solution | |-------|-------|----------| | Build fails after optimization | Invalid code or config change | Revert that optimization | | No size reduction | Optimization ineffective | Discard it | | Analyzer unavailable | Tooling missing | Continue with manual inspection |
shared/references/ci_tool_detection.mdMANDATORY READ: Load shared/references/coordinator_summary_contract.md
Emit a modernization-worker summary envelope.
Managed mode:
ln-830 passes deterministic runId and exact summaryArtifactPathsummaryArtifactPathStandalone mode:
runId and summaryArtifactPath.hex-skills/runtime-artifacts/runs/{run_id}/modernization-worker/ln-832--{identifier}.jsonMonitor (2.1.98+): For build commands in keep/discard loop expected >30s, use Monitor. Fallback: Bash(run_in_background=true).
modernization-worker summary artifact written to the managed or standalone pathVersion: 1.0.0 Last Updated: 2026-03-08
testing
Drafts and publishes fact-checked GitHub Discussions announcements. Use for releases, updates, or project news; not for release creation or issue responses.
testing
Prepares and publishes a tagged GitHub release from repository evidence. Use for an explicit release request; not for ordinary commits, packages, or community news.
testing
Validates, commits, pushes, and remotely verifies approved repository changes. Use when publication is requested; not for releases, package publishing, or announcements.
development
Reviews standalone skills and their configured distribution surfaces before publication. Use for skill release readiness; not for product code or implementation-plan review.