Communitygithub.com

nextjs-turbopack

Next.js 16+ と Turbopack の概要 — インクリメンタルバンドル、ファイルシステムキャッシュ、開発速度の向上、Turbopack と webpack の使い分けについて。

nextjs-turbopack とは?

このスキルは、Next.js 16 以降でデフォルト開発サーバーとして採用された Turbopack について詳しく解説します。Rust で書かれたインクリメンタルバンドラーである Turbopack は、開発時のコールドスタートやホットモジュールリプレイスメント(HMR)を大幅に高速化し、特に大規模プロジェクトでは最大 5~14 倍の速度向上が見込めます。従来の webpack(開発時)との使い分けや、プロダクションビルドでの注意点、Next.js 16.1 以降で利用可能な Bundle Analyzer 実験機能についてもカバーしています。また、Next.js 16 からミドルウェアのファイル名が `proxy.ts` に変更された点も重要で、誤って `middleware.ts` にリネームしないように注意する必要があります。開発の高速化、HMR の最適化、バンドルサイズの分析に役立つ実用的なガイドです。

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

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Next.js と Turbopack

Next.js 16 以降では、ローカル開発に Turbopack がデフォルトで使用されます。Turbopack は Rust で書かれたインクリメンタルバンドラーであり、開発サーバーの起動とホットアップデートを大幅に高速化します。

使用すべきタイミング

  • Turbopack(開発デフォルト): 日々の開発に使用します。特に大規模アプリでコールドスタートと HMR が高速化されます。
  • Webpack(開発レガシー): Turbopack のバグに遭遇した場合や、開発時に webpack 専用プラグインに依存している場合のみ使用します。--webpack または --no-turbopack フラグで無効化します(使用している Next.js バージョンのドキュメントを確認してください)。
  • プロダクション: プロダクションビルド(next build)の動作は Next.js のバージョンによって Turbopack または webpack のどちらかを使用します。公式ドキュメントでバージョンごとの動作を確認してください。

使用する場面: 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 とサーバーコンポーネントを優先してください。

ミドルウェアのファイル名

Next.js 16 では、ミドルウェアのファイル名が従来の middleware.ts から proxy.ts に変更されました。

  • Next.js 16 以降: プロジェクトルートに proxy.ts を使用
  • Next.js 16 未満: プロジェクトルートに middleware.ts を使用

ファイル名の変更は Next.js のバージョン に依存し、使用するバンドラー(Turbopack または webpack)には依存しません。常に確認しているバージョンの公式ドキュメントを参照してください。

Next.js 16 プロジェクトで proxy.ts を名前間違いやミドルウェアファイルの欠落として報告しないでください。 このファイルは正しく意図されたものです。middleware.ts へのリネームを提案するとミドルウェアの実行が壊れます。

参考: Next.js proxy ドキュメント

ベストプラクティス

  • 安定した Turbopack とキャッシュ動作を得るために、最新の Next.js 16.x を使用してください。
  • 開発が遅い場合は、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.

関連スキル