nextjs-bundle-optimizer
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "nextjs-bundle-optimizer" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-adca23ed1fc862609693c622980218a31afd53c705b8b70a4d796575264af7da. Verify the upstream source and version against https://github.com/pproenca/dot-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Bundle-size and build-time optimization process for Next.js 16: a data-driven iteration loop (measure baseline → analyze issues → apply a single optimization → re-measure → verify no functionality breakage: build, types, tests, and performance → commit or rollback). Defaults to Turbopack and falls back to webpack when the project has not migrated. Triggered by conditions such as “large first-page JS”, bundle size, long build times, slow page TTI, reducing bundle size, tree-shaking, or when the user provides next experimental-analyze / @next/bundle-analyzer output—even if the user did not explicitly ask for “optimization”.
Introduction source: third_party · pproenca · 0.0.1 Reference
SkillPi interpretation
- Tasks
- 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.
- Software, accounts and paid services
- Next.js 16+ project (the skill auto-detects from `package.json`). `git` (the workflow uses commits as checkpoints and revert as rollback). `jq` available on PATH (used by analyze/compare scripts). A clean working tree before starting (the verify step uses `git status` to confirm). For projects still on Next.js 15 or earlier in webpack mode: the skill detects this and uses `@next/bundle-analyzer` instead of `experimental-analyze`. See gotchas.md.
- Testing
- Not tested
Browse files
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.
Current listing version
0.0.1
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决 Next.js 开发中的核心痛点:包体积过大和构建时间过长
- 提供数据驱动的迭代优化流程,确保每次变更都可验证
- 适用于广泛的前端开发者和 Next.js 项目
Highlights
- 触发词覆盖全面,包括多种用户可能使用的表达方式
- 能够识别用户分享的分析器输出作为触发信号
- 边界清晰,不易与其他 Skill 重叠
Highlights
- Workflow Overview 清晰展示了六步迭代流程
- Quick Reference 提供了脚本和优化配方的快速查阅
- 文档结构完整,包含 When to Apply、Why iterative、Prerequisites 等必要章节
Highlights
- 使用 Next.js 官方工具链,确保兼容性和可靠性
- 通过 git commit/revert 实现可靠的回滚机制
- verify.sh 提供完整的验证保障,包括构建、类型检查、测试等
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Invoke commands or scripts
Read the script and arguments first. Use ordinary privileges and a scoped directory; confirm installation or execution in your host tool.
Mentioned in main document · lines 41
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Next.js 16+ project (the skill auto-detects from `package.json`). `git` (the workflow uses commits as checkpoints and revert as rollback). `jq` available on PATH (used by analyze/compare scripts). A clean working tree before starting (the verify step uses `git status` to confirm). For projects still on Next.js 15 or earlier in webpack mode: the skill detects this and uses `@next/bundle-analyzer` instead of `experimental-analyze`. See gotchas.md.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.