nextjs-bundle-optimizer
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "nextjs-bundle-optimizer":https://skillpi.com/zh/skills/deepskill-adca23ed1fc862609693c622980218a31afd53c705b8b70a4d796575264af7da。安装前核对上游来源和版本:https://github.com/pproenca/dot-skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
针对 Next.js 16 的包体积与构建时间优化流程:以数据驱动的迭代循环(测量基线 → 分析问题 → 应用单一优化 → 重新测量 → 验证未破坏功能:构建、类型、测试与性能 → 提交或回滚)。默认使用 Turbopack,项目未迁移时回退到 webpack 工具链。适用于触发条件如“首屏 JS 体积过大”、包体积、构建耗时、页面 TTI 慢、减小包体积、Tree-shaking 或提供了 next experimental-analyze / @next/bundle-analyzer 输出的情况,即便未明确请求“优化”。
介绍来源: third_party · pproenca · 0.0.1 参考来源
SkillPi 解读
- 能完成的任务
- 翻译待完成,请参阅来源文档。
- 软件、账号及付费要求
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: nextjs-bundle-optimizer
description: "Next.js 16 bundle-size and build-time optimization — runs a data-driven iteration loop: measure baseline → analyze top offenders → apply ONE recipe → re-measure → verify nothing broke (build + types + tests + no regression) → commit or revert. Built for Next.js 16 with Turbopack default, and falls back to webpack-mode tooling when the project hasn't migrated yet. Triggers on phrases like \"First Load JS is huge\", \"bundle size\", \"build takes too long\", \"page is slow to TTI\", \"reduce bundle\", \"tree-shake\", or when the user shares output from `next experimental-analyze` / `@next/bundle-analyzer` — even if the user doesn't say \"optimize\" explicitly."Next.js Bundle & Build-Time Optimizer
Data-driven optimization loop for Next.js 16 applications. The skill orchestrates next experimental-analyze, builds, type checks, and tests to make verifiable improvements one change at a time.
When to Apply
Use this skill when:
- The user wants to reduce bundle size / First Load JS / route bundles in a Next.js 16 app.
- Production builds are slow and the user wants to diagnose and fix the bottleneck.
- The user shares analyzer output, a screenshot of the treemap, or asks "why is
<X>so big?" - A new dependency was added and bundles grew — they want to understand why and unwind it.
- The user wants to set a performance budget and enforce it iteratively.
Why iterative (not "apply all optimizations at once")
Bundle optimization is full of foot-guns. Examples:
- Moving a "client-only" dep behind
next/dynamiccan break SSR consumers that depended on its presence at first paint. experimental.optimizePackageImportswith the wrong package can mis-resolve subpath exports.- Aggressive
modularizeImportsregex rewrites can hit unintended modules. - Narrowing the polyfill target can break older mobile browsers in production.
The only reliable way is: one change, measure, verify, commit (or revert). This skill enforces that discipline through scripts.
Prerequisites
- Next.js 16+ project (the skill auto-detects from
package.json). git(the workflow uses commits as checkpoints and revert as rollback).jqavailable on PATH (used by analyze/compare scripts).- A clean working tree before starting (the verify step uses
git statusto confirm). - For projects still on Next.js 15 or earlier in webpack mode: the skill detects this and uses
@next/bundle-analyzerinstead ofexperimental-analyze. See gotchas.md.
Setup
On first use, run:
bash scripts/baseline.sh --setup
This walks through config.json interactively. If config.json already has values, scripts use those and skip the prompts.
Workflow Overview
┌── 1. baseline ──┐ Clean build, snapshot bundles + timing → baselines/{timestamp}/
│ │
│ 2. analyze ───┤ Run `next experimental-analyze --output`, extract top offenders
│ │
│ 3. diagnose ──┤ Map each offender to a recipe in references/optimizations.md
│ │
│ ── apply ─────┤ User (or agent) applies ONE recipe. Skill helps draft the change.
│ │
│ 4. measure ───┤ Re-build, re-analyze, save to iterations/{n}/
│ │
│ 5. compare ───┤ Diff vs baseline; flag regressions; print delta table
│ │
│ 6. verify ────┤ Build + tsc + tests + no overall regression. Hard PASS/FAIL.
│ │
│ commit OR ────┘ `git commit` (PASS+improvement) or `git revert` (FAIL/no win)
│ revert
│
└── loop back to step 2 with new baseline if you want a fresh measurement point.
Read references/workflow.md for the detailed loop with error handling, rollback procedures, and what each script's output looks like.
Quick Reference
Scripts (run from the Next.js app root)
| Script | Purpose | Output |
|---|---|---|
scripts/baseline.sh |
Establish the reference point | baselines/{ts}/{bundle,timing,manifest}.json |
scripts/analyze.sh |
Run analyzer, parse top offenders | iterations/{n}/findings.json |
scripts/diagnose.sh [findings.json] |
Map findings → recipes | stdout: prioritized recipe list |
scripts/measure.sh |
Re-measure after a change | iterations/{n}/{bundle,timing}.json |
scripts/compare.sh [baseline] [current] |
Diff snapshots | stdout: delta table; exit 1 on regression |
scripts/verify.sh |
Full verification | exit 0 = safe to commit, exit 1 = revert |
Optimization Recipes
references/optimizations.md catalogs recipes by analyzer signal:
Bundle size
- Barrel-import bloat →
experimental.optimizePackageImports(webpack) / auto in Turbopack - Heavy client lib pulled in on every route →
next/dynamic({ ssr: false }) - Server-only lib imported from a client component → move to Server Component
- Duplicate dependency versions → dedupe via
overrides/resolutions - Polyfill bloat → tighten
browserslist - Per-icon imports for icon libraries
Build time
- Enable
experimental.turbopackFileSystemCacheForBuild - Narrow
transpilePackages(overuse balloons compile time) - Split
tsc --noEmitfromnext buildin CI - Identify single-file bottlenecks with
NEXT_TURBOPACK_TRACING=1
Each recipe documents: signal → fix → expected impact → verify step.
Gotchas
See gotchas.md for accumulated failure points. Initially seeded with the most common Next.js 16 traps:
next buildno longer prints First Load JS — don't grep build output for it.optimizePackageImportsis a no-op under Turbopack (default in 16) — Turbopack auto-optimizes.- Comparing build times needs cache state controlled — either delete
.next/(cold) or pre-warm (warm).
Related Skills
vercel:nextjs— general Next.js App Router guidance; consult for refactoring decisions while applying recipes.vercel:turbopack— for build-time debugging beyond what this skill covers.vercel:next-cache-components— when a recipe touches caching boundaries.
当前收录版本
0.0.1
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 解决 Next.js 开发中的核心痛点:包体积过大和构建时间过长
- 提供数据驱动的迭代优化流程,确保每次变更都可验证
- 适用于广泛的前端开发者和 Next.js 项目
亮点
- 触发词覆盖全面,包括多种用户可能使用的表达方式
- 能够识别用户分享的分析器输出作为触发信号
- 边界清晰,不易与其他 Skill 重叠
亮点
- Workflow Overview 清晰展示了六步迭代流程
- Quick Reference 提供了脚本和优化配方的快速查阅
- 文档结构完整,包含 When to Apply、Why iterative、Prerequisites 等必要章节
亮点
- 使用 Next.js 官方工具链,确保兼容性和可靠性
- 通过 git commit/revert 实现可靠的回滚机制
- verify.sh 提供完整的验证保障,包括构建、类型检查、测试等
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
调用命令或脚本
先读脚本与参数,使用普通权限和限定目录;安装或执行前由使用工具再次确认。
主文档提及 · 第 41 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
翻译待完成,请参阅来源文档。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。