Unverified Commit 7a8945c5 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Use --analyze for combined build and bundle analysis

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent d014bbb9
...@@ -45,6 +45,26 @@ pnpm next analyze ...@@ -45,6 +45,26 @@ pnpm next analyze
bunx next analyze bunx next analyze
``` ```
To produce a production build **and** save bundle analysis in one command, use `next build --analyze` instead:
```bash filename="Terminal" package="npm"
npx next build --analyze
```
```bash filename="Terminal" package="yarn"
yarn next build --analyze
```
```bash filename="Terminal" package="pnpm"
pnpm next build --analyze
```
```bash filename="Terminal" package="bun"
bunx next build --analyze
```
Build analysis is saved to `.next/diagnostics/analyze`. Browser source maps are only published if enabled in your build configuration. The separate `next analyze` command opens the interactive analyzer without producing a production build.
### Step 2: Filter and inspect modules ### Step 2: Filter and inspect modules
Within the UI, you can filter by route, environment (client or server), and type (JavaScript, CSS, JSON), or search by file: Within the UI, you can filter by route, environment (client or server), and type (JavaScript, CSS, JSON), or search by file:
......
...@@ -99,7 +99,7 @@ The following options are available for the `next build` command: ...@@ -99,7 +99,7 @@ The following options are available for the `next build` command:
| `[directory]` | A directory on which to build the application. If not provided, the current directory will be used. | | `[directory]` | A directory on which to build the application. If not provided, the current directory will be used. |
| `--turbopack` | Force enable [Turbopack](/docs/app/api-reference/turbopack) (enabled by default). Also available as `--turbo`. | | `--turbopack` | Force enable [Turbopack](/docs/app/api-reference/turbopack) (enabled by default). Also available as `--turbo`. |
| `--webpack` | Build using the bundled Webpack. | | `--webpack` | Build using the bundled Webpack. |
| `--analyze` | Generate bundle analysis data for the interactive analyzer during a Turbopack build. | | `--analyze` | Build with Turbopack and write bundle analysis to `.next/diagnostics/analyze`. Does not publish additional browser source maps. |
| `-d` or `--debug` | Enables a more verbose build output. With this flag enabled additional build output like rewrites, redirects, and headers will be shown. | | `-d` or `--debug` | Enables a more verbose build output. With this flag enabled additional build output like rewrites, redirects, and headers will be shown. |
| `--profile` | Enables production [profiling for React](https://react.dev/reference/react/Profiler). | | `--profile` | Enables production [profiling for React](https://react.dev/reference/react/Profiler). |
| `--no-mangling` | Disables [mangling](https://en.wikipedia.org/wiki/Name_mangling). This may affect performance and should only be used for debugging purposes. | | `--no-mangling` | Disables [mangling](https://en.wikipedia.org/wiki/Name_mangling). This may affect performance and should only be used for debugging purposes. |
......
...@@ -565,7 +565,7 @@ describe('next analyze', () => { ...@@ -565,7 +565,7 @@ describe('next analyze', () => {
readFileSync(path.join(staticDir, file)) readFileSync(path.join(staticDir, file))
) )
const result = await next.build({ args: ['--experimental-analyze'] }) const result = await next.build({ args: ['--analyze'] })
expect(result.exitCode).toBe(0) expect(result.exitCode).toBe(0)
expect(assets()).toEqual(normalAssets) expect(assets()).toEqual(normalAssets)
for (const [index, file] of normalAssets.entries()) { for (const [index, file] of normalAssets.entries()) {
...@@ -606,9 +606,7 @@ describe('next analyze', () => { ...@@ -606,9 +606,7 @@ describe('next analyze', () => {
const normalContents = normalFiles.map((file) => const normalContents = normalFiles.map((file) =>
readFileSync(path.join(staticDir, file)) readFileSync(path.join(staticDir, file))
) )
expect( expect((await next.build({ args: ['--analyze'] })).exitCode).toBe(0)
(await next.build({ args: ['--experimental-analyze'] })).exitCode
).toBe(0)
expect(files()).toEqual(normalFiles) expect(files()).toEqual(normalFiles)
for (const [index, file] of normalFiles.entries()) { for (const [index, file] of normalFiles.entries()) {
expect(readFileSync(path.join(staticDir, file))).toEqual( expect(readFileSync(path.join(staticDir, file))).toEqual(
...@@ -619,6 +617,21 @@ describe('next analyze', () => { ...@@ -619,6 +617,21 @@ describe('next analyze', () => {
await next.patchFile('next.config.js', originalConfig) await next.patchFile('next.config.js', originalConfig)
} }
}, 180_000) }, 180_000)
it('advertises --analyze while accepting the legacy build flag', async () => {
const help = await next.runCommand(['build', '--help'])
expect(help.exitCode).toBe(0)
expect(help.stdout).toContain('--analyze')
expect(help.stdout).not.toContain('--experimental-analyze')
const result = await next.build({ args: ['--experimental-analyze'] })
expect(result.exitCode).toBe(0)
expect(
existsSync(
path.join(next.testDir, '.next/diagnostics/analyze/data/analyze.data')
)
).toBe(true)
}, 180_000)
;['-o', '--output'].forEach((flag) => { ;['-o', '--output'].forEach((flag) => {
describe(`with ${flag} flag`, () => { describe(`with ${flag} flag`, () => {
it('writes output to .next/diagnostics/analyze path', async () => { it('writes output to .next/diagnostics/analyze path', async () => {
......
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