ln-832-bundle-optimizer by levnikolaevich/claude-code-skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-832-bundle-optimizer路径说明: 文件路径(
shared/、references/、../ln-*)是相对于技能仓库根目录的。如果在当前工作目录未找到,请定位此 SKILL.md 文件所在目录并向上返回一级以找到仓库根目录。如果缺少shared/目录,请通过 WebFetch 从https://raw.githubusercontent.com/levnikolaevich/claude-code-skills/master/skills/{path}获取文件。
类型: L3 Worker 类别: 8XX 优化 父级: ln-830-code-modernization-coordinator
减小 JavaScript/TypeScript 包体积。指标:包大小(字节)。每项优化都通过采用保留/丢弃模式的构建进行验证。仅适用于 JS/TS 项目。
| 方面 | 详情 |
|---|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| JS/TS 项目(根据 package.json 自动检测) |
| 输出 | 更小的包、优化报告 |
| 范围 | 仅限 JS/TS(其他技术栈跳过) |
阶段: 预检 → 基准 → 分析 → 优化循环 → 报告
| 检查项 | 是否必需 | 缺失时的操作 |
|---|---|---|
| 存在 package.json | 是 | 阻止(非 JS/TS 项目) |
| 构建命令可用 | 是 | 阻止(需要构建以测量大小) |
| 存在 dist/ 或 build/ 输出目录 | 是 | 先运行构建以建立基准 |
| Git 状态干净 | 是 | 阻止(需要干净的基准以便回滚) |
必读: 加载 shared/references/ci_tool_detection.md — 使用其“构建”部分来检测构建命令。
必读: 加载 shared/references/git_worktree_fallback.md — 使用 ln-832 行。
1. 运行构建:npm run build(或检测到的构建命令)
2. 测量:dist/ 或 build/ 目录的总大小
3. 记录:baseline_bytes, baseline_files
| 指标 | 方法 |
|---|---|
| 总大小 | 输出目录中所有文件的总和 |
| 每个块的大小 | 单个 JS/CSS 文件的大小 |
| 排除源映射 | 不计算 .map 文件 |
| 检查项 | 工具 | 发现内容 |
|---|---|---|
| 未使用的依赖 | npx depcheck | package.json 中存在但未在任何地方导入的包 |
| 包构成分析 | npx vite-bundle-visualizer 或 webpack-bundle-analyzer | 大型依赖项、重复项 |
| Tree-shaking 缺口 | 手动扫描 | 使用 import * as 而非具名导入 |
| 代码分割 | 路由分析 | 初始包过大,可延迟加载的路由 |
| 类别 | 示例 | 典型节省 |
|---|---|---|
| 移除未使用的依赖 | 安装了 lodash 但未导入 | 每个依赖 10-50KB |
| 具名导入 | import { debounce } from 'lodash-es' 对比 import _ from 'lodash' | 50-200KB |
| 更轻量的替代品 | 用 date-fns 替代 moment | 50-300KB |
| 动态导入 | React.lazy(() => import('./HeavyComponent')) | 减少初始加载量 |
| CSS 优化 | 清除未使用的 CSS、压缩 | 10-100KB |
对于每项优化 (O1..ON):
1. 应用:进行更改(移除依赖、重写导入、添加延迟加载)
2. 构建:运行构建命令
如果构建失败 → 丢弃(回滚)→ 下一项优化
3. 测量:新的包大小
4. 比较:
如果 new_bytes < baseline_bytes → 保留(新基准 = new_bytes)
如果 new_bytes >= baseline_bytes → 丢弃(回滚,无改进)
5. 记录:记录结果
| 条件 | 操作 |
|---|---|
| 所有优化处理完毕 | 停止 — 进入报告阶段 |
| 连续 3 次丢弃(大小未减小) | 停止 — 达到平台期:“未找到进一步的缩减” |
| 构建基础设施损坏 | 停止 — 回滚到最后一次保留的状态,报告部分结果 |
| 包大小已低于目标大小 | 停止 — “包已优化” |
| 条件 | 决策 |
|---|---|
| 构建失败 | 丢弃 |
| 包变小 | 保留(更新基准) |
| 包相同或变大 | 丢弃 |
| 顺序 | 类别 | 原因 |
|---|---|---|
| 1 | 移除未使用的依赖 | 最安全,立即节省 |
| 2 | 具名导入 / tree-shaking | 中等风险,节省效果良好 |
| 3 | 更轻量的替代品 | 风险较高(API 变更) |
| 4 | 动态导入 / 代码分割 | 结构性变更,需仔细测试 |
| 5 | CSS 优化 | 优先级最低 |
| 字段 | 描述 |
|---|---|
| project | 项目路径 |
| baseline_bytes | 原始包大小 |
| final_bytes | 最终包大小 |
| reduction_bytes | 节省的字节数 |
| reduction_percent | 减少的百分比 |
| optimizations_applied | 应用的优化数量 |
| optimizations_discarded | 丢弃的数量 + 原因 |
| details[] | 每项优化详情:类别、描述、节省的字节数 |
| deps_removed[] | 移除的未使用依赖 |
Options:
# Build
build_command: "" # 从 ci_tool_detection.md 自动检测
output_dir: "" # 自动检测:dist/ 或 build/
# Analysis
run_depcheck: true
run_bundle_analyzer: false # 会打开浏览器,在 CI 中跳过
# Optimization scope
remove_unused_deps: true
fix_tree_shaking: true
suggest_alternatives: true
add_code_splitting: false # 结构性变更,需手动启用
# Verification
run_build: true
| 错误 | 原因 | 解决方案 |
|---|---|---|
| depcheck 不可用 | 未安装 | npx depcheck(无需安装即可运行) |
| 移除后构建失败 | 依赖在动态导入/配置中使用 | 回滚,标记为误报 |
| 无输出目录 | 非标准构建设置 | 检查 package.json 的输出配置 |
| 非 JS/TS 项目 | 无 package.json | 完全跳过并输出信息消息 |
shared/references/ci_tool_detection.md(构建检测)版本: 1.0.0 最后更新: 2026-03-08
每周安装数
76
仓库
GitHub 星标数
245
首次出现
2026年3月8日
安全审计
安装于
cursor73
claude-code71
github-copilot71
amp71
cline71
codex71
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 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.
| Aspect | Details |
|---|---|
| Input | JS/TS project (auto-detect from package.json) |
| Output | Smaller bundle, optimization report |
| Scope | JS/TS only (skip for other stacks) |
Phases: Pre-flight → Baseline → Analyze → Optimize Loop → Report
| 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) |
MANDATORY READ: Load shared/references/ci_tool_detection.md — use Build section for build command detection.
MANDATORY READ: Load shared/references/git_worktree_fallback.md — use ln-832 row.
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
| 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 | npx depcheck | Packages in package.json not imported anywhere |
| Bundle composition | npx vite-bundle-visualizer or webpack-bundle-analyzer | Large dependencies, duplicates |
| Tree-shaking gaps | Manual scan | import * as instead of named imports |
| Code splitting | Route analysis | Large initial bundle, lazy-loadable routes |
| Category | Example | Typical Savings |
|---|---|---|
| Remove unused deps | lodash installed but not imported | 10-50KB per dep |
| Named imports | import { debounce } from 'lodash-es' vs import _ from 'lodash' | 50-200KB |
| Lighter alternatives | date-fns instead of moment | 50-300KB |
| Dynamic imports | React.lazy(() => import('./HeavyComponent')) |
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 | Action |
|---|---|
| All optimizations processed | STOP — proceed to Report |
| 3 consecutive DISCARDs (no size reduction) | STOP — plateau: "No further reductions found" |
| Build infrastructure breaks | STOP — revert to last KEEP, report partial results |
| Bundle already below target size | STOP — "Bundle already optimized" |
| 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 | npx depcheck (runs without install) |
| 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 (build detection)Version: 1.0.0 Last Updated: 2026-03-08
Weekly Installs
76
Repository
GitHub Stars
245
First Seen
Mar 8, 2026
Security Audits
Gen Agent Trust HubPassSocketWarnSnykWarn
Installed on
cursor73
claude-code71
github-copilot71
amp71
cline71
codex71
GitHub Actions 官方文档查询助手 - 精准解答 CI/CD 工作流问题
45,200 周安装
ActiveCampaign自动化集成指南:通过Rube MCP实现CRM与营销自动化
72 周安装
通过Rube MCP实现Make自动化:集成Composio工具包管理场景与操作
72 周安装
Microsoft Teams自动化指南:通过Rube MCP实现频道消息、聊天与会议管理
72 周安装
Electrobun 最佳实践:TypeScript + Bun 跨平台桌面应用开发指南
72 周安装
ATXP Memory:AI代理记忆管理工具 - 云端备份与本地向量搜索
72 周安装
Brave Search Spellcheck API:智能拼写检查与查询纠正,提升搜索准确性
72 周安装
| Reduce initial load |
| CSS optimization | Purge unused CSS, minify | 10-100KB |