$npx -y skills add affaan-m/ECC --skill nextjs-turbopackNext.js 16+ and Turbopack — incremental bundling, FS caching, dev speed, and when to use Turbopack vs webpack.
| 1 | # Next.js and Turbopack |
| 2 | |
| 3 | Next.js 16+ uses Turbopack by default for local development: an incremental bundler written in Rust that significantly speeds up dev startup and hot updates. |
| 4 | |
| 5 | ## When to Use |
| 6 | |
| 7 | - **Turbopack (default dev)**: Use for day-to-day development. Faster cold start and HMR, especially in large apps. |
| 8 | - **Webpack (legacy dev)**: Use only if you hit a Turbopack bug or rely on a webpack-only plugin in dev. Disable with `--webpack` (or `--no-turbopack` depending on your Next.js version; check the docs for your release). |
| 9 | - **Production**: Production build behavior (`next build`) may use Turbopack or webpack depending on Next.js version; check the official Next.js docs for your version. |
| 10 | |
| 11 | Use when: developing or debugging Next.js 16+ apps, diagnosing slow dev startup or HMR, or optimizing production bundles. |
| 12 | |
| 13 | ## How It Works |
| 14 | |
| 15 | - **Turbopack**: Incremental bundler for Next.js dev. Uses file-system caching so restarts are much faster (e.g. 5–14x on large projects). |
| 16 | - **Default in dev**: From Next.js 16, `next dev` runs with Turbopack unless disabled. |
| 17 | - **File-system caching**: Restarts reuse previous work; cache is typically under `.next`; no extra config needed for basic use. |
| 18 | - **Bundle Analyzer (Next.js 16.1+)**: Experimental Bundle Analyzer to inspect output and find heavy dependencies; enable via config or experimental flag (see Next.js docs for your version). |
| 19 | |
| 20 | ## Examples |
| 21 | |
| 22 | ### Commands |
| 23 | |
| 24 | ```bash |
| 25 | next dev |
| 26 | next build |
| 27 | next start |
| 28 | ``` |
| 29 | |
| 30 | ### Usage |
| 31 | |
| 32 | Run `next dev` for local development with Turbopack. Use the Bundle Analyzer (see Next.js docs) to optimize code-splitting and trim large dependencies. Prefer App Router and server components where possible. |
| 33 | |
| 34 | ## Best Practices |
| 35 | |
| 36 | - Stay on a recent Next.js 16.x for stable Turbopack and caching behavior. |
| 37 | - If dev is slow, ensure you're on Turbopack (default) and that the cache isn't being cleared unnecessarily. |
| 38 | - For production bundle size issues, use the official Next.js bundle analysis tooling for your version. |