Communitygithub.com

Next.js 與 Turbopack

Next.js 16+ 與 Turbopack — 增量式打包、檔案系統快取、開發速度,以及何時使用 Turbopack 與 webpack。

Next.js 與 Turbopack 是什麼?

這項技能詳細說明 Next.js 16 以上版本中 Turbopack 的用法與優勢。Turbopack 是基於 Rust 的增量式打包工具,能大幅加快開發伺服器的啟動速度與熱模組替換(HMR),尤其適合大型專案。文件中涵蓋了何時應使用 Turbopack(預設開發模式)與何時須回退至 webpack(例如遇到 Turbopack 錯誤或依賴 webpack-only 外掛時),也說明生產環境建置的行為因版本而異。此外,技能還介紹了檔案系統快取機制(預設啟用,無需額外設定)、Next.js 16.1+ 的實驗性 Bundle Analyzer,以及 Next.js 16 中 Middleware 檔案更名為 `proxy.ts` 的重要變更。該技能支援所有 Next.js 開發者、DevOps 工程師及 AI 代理,協助診斷緩慢的開發啟動、HMR 問題,或最佳化生產環境的打包結果。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/nextjs-turbopack

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Next.js 與 Turbopack 是做什麼的?

從 Next.js 16 開始,本機開發預設使用 Turbopack:這是一個以 Rust 撰寫的增量式打包工具,能顯著加速開發啟動與熱更新。

使用時機

  • Turbopack(預設開發模式):日常開發使用。冷啟動和 HMR 速度更快,尤其在大型應用程式中。
  • Webpack(傳統開發模式):僅在遇到 Turbopack 錯誤或依賴 webpack-only 外掛時使用。可透過 --webpack 參數(或 --no-turbopack,視 Next.js 版本而定;請查閱您版本的官方文件)停用 Turbopack。
  • 生產環境:生產環境建置行為(next build)可能使用 Turbopack 或 webpack,取決於 Next.js 版本;請查閱對應版本的官方 Next.js 文件。

適用於:開發或除錯 Next.js 16+ 應用程式、診斷開發啟動速度慢或 HMR 問題,或最佳化生產環境的打包結果。

運作方式

  • Turbopack:Next.js 開發模式的增量式打包工具。利用檔案系統快取,重新啟動速度更快(大型專案可達 5–14 倍加速)。
  • 開發模式預設:從 Next.js 16 開始,next dev 預設使用 Turbopack,除非手動停用。
  • 檔案系統快取:重新啟動時會重複使用先前的工作成果;快取通常位於 .next 目錄下;基本使用無需額外設定。
  • Bundle Analyzer(Next.js 16.1+):實驗性 Bundle Analyzer,用於檢查輸出內容並找出大型依賴;可透過設定或實驗性旗標啟用(請參閱對應版本的 Next.js 文件)。

範例

指令

next dev
next build
next start

使用方式

執行 next dev 以 Turbopack 進行本機開發。使用 Bundle Analyzer(請參閱 Next.js 文件)來最佳化程式碼分割並縮減大型依賴。盡可能使用 App Router 與伺服器元件。

Middleware 檔案命名

Next.js 16 引入了 proxy.ts 作為 middleware 的檔案名稱,取代了舊的 middleware.ts 慣例:

  • Next.js 16+:在專案根目錄使用 proxy.ts
  • Next.js 16 之前:在專案根目錄使用 middleware.ts

此檔案名稱變更與 Next.js 版本 有關,而非所使用的打包工具(Turbopack 或 webpack)。請務必查閱您所使用版本的官方文件。

請勿在 Next.js 16 專案中將 proxy.ts 標記為命名錯誤或遺失的 middleware 檔案。 此檔案是正確且刻意使用的。建議重新命名為 middleware.ts 將導致 middleware 執行中斷。

參考資料:Next.js proxy 文件

最佳實務

  • 保持在最新的 Next.js 16.x 版本,以獲得穩定的 Turbopack 與快取行為。
  • 如果開發模式速度緩慢,請確認您正使用 Turbopack(預設),且快取未被不必要地清除。
  • 對於生產環境的包大小問題,請使用該版本 Next.js 官方提供的打包分析工具。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相關技能