Unverified Commit de05823a authored by Sam Poder's avatar Sam Poder Committed by GitHub

Add a `turbopackChunking` documentation page for pages router (#96698)

These options are also supported on pages router but were missing a
documentation page. Component chunks are not supported.
parent b87f7b4a
...@@ -4,13 +4,29 @@ description: Configure how Turbopack splits your client-side JavaScript into chu ...@@ -4,13 +4,29 @@ description: Configure how Turbopack splits your client-side JavaScript into chu
version: experimental version: experimental
--- ---
{/* The content of this doc is shared between the app and pages router. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
<AppOnly>
`experimental.turbopackChunking` lets you configure Turbopack's production JavaScript `experimental.turbopackChunking` lets you configure Turbopack's production JavaScript
chunker. These options allow you to change the assumptions the chunker makes about user chunker. These options allow you to change the assumptions the chunker makes about user
behaviour, tweak the raw size thresholds it uses, and enable the experimental component behaviour, tweak the raw size thresholds it uses, and enable the experimental component
chunks feature. chunks feature.
</AppOnly>
<PagesOnly>
`experimental.turbopackChunking` lets you configure Turbopack's production JavaScript
chunker. These options allow you to change the assumptions the chunker makes about user
behaviour and tweak the raw size thresholds it uses.
</PagesOnly>
By default, Turbopack's chunking is configured as follows: By default, Turbopack's chunking is configured as follows:
<AppOnly>
```ts filename="next.config.ts" switcher ```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
...@@ -46,6 +62,43 @@ const nextConfig = { ...@@ -46,6 +62,43 @@ const nextConfig = {
module.exports = nextConfig module.exports = nextConfig
``` ```
</AppOnly>
<PagesOnly>
```ts filename="next.config.ts" switcher
import type { NextConfig } from 'next'
const nextConfig = {
experimental: {
turbopackChunking: {
minChunkSize: 50000,
maxChunkCountPerGroup: 40,
maxMergeChunkSize: 200000,
},
},
} satisfies NextConfig
export default nextConfig
```
```js filename="next.config.js" switcher
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
turbopackChunking: {
minChunkSize: 50000,
maxChunkCountPerGroup: 40,
maxMergeChunkSize: 200000,
},
},
}
module.exports = nextConfig
```
</PagesOnly>
## Size Thresholds ## Size Thresholds
The following options control how aggressively Turbopack merges chunks and how large a chunk is The following options control how aggressively Turbopack merges chunks and how large a chunk is
...@@ -69,6 +122,8 @@ When merging chunks, the trade-off being made is an improvement to performance o ...@@ -69,6 +122,8 @@ When merging chunks, the trade-off being made is an improvement to performance o
loads at the cost of navigation performance. This is because each additional network request loads at the cost of navigation performance. This is because each additional network request
being made is costly, however, smaller chunks are more likely to be re-usable across pages. being made is costly, however, smaller chunks are more likely to be re-usable across pages.
<AppOnly>
## Component Chunks ## Component Chunks
Producing component chunks is an experimental feature that aims to give you the initial Producing component chunks is an experimental feature that aims to give you the initial
...@@ -86,6 +141,8 @@ This avoids re-downloading JavaScript the browser already has when navigating. ...@@ -86,6 +141,8 @@ This avoids re-downloading JavaScript the browser already has when navigating.
this size are folded into a single component instead of being emitted on their own, this size are folded into a single component instead of being emitted on their own,
to avoid producing many tiny chunks. to avoid producing many tiny chunks.
</AppOnly>
## Heuristics ## Heuristics
These change the assumptions the chunker makes when weighing whether merging two These change the assumptions the chunker makes when weighing whether merging two
......
---
title: turbopackChunking
description: Configure how Turbopack splits your client-side JavaScript into chunks in production.
version: experimental
source: app/api-reference/config/next-config-js/turbopackChunking
---
{/* DO NOT EDIT. The content of this doc is generated from the source above. To edit the content of this page, navigate to the source page in your editor. You can use the `<PagesOnly>Content</PagesOnly>` component to add content that is specific to the Pages Router. Any shared content should not be wrapped in a component. */}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment