Skip to content

Commit

Permalink
feat(nextjs): add experimental-build-mode option to support compile o…
Browse files Browse the repository at this point in the history
…nly (#26465)

## Current Behavior

The nextjs build executor does not support all build flags such as
`--experimental-build-mode` (see
https://nextjs.org/docs/app/api-reference/next-cli#build).

## Expected Behavior

For certain deployment models (e.g. mult-environment builds), it is
helpful to only compile but not generate pages at build time. See
vercel/next.js#46544 for a discussion.

---------

Co-authored-by: Emily Xiong <[email protected]>
Co-authored-by: Craigory Coppola <[email protected]>
  • Loading branch information
3 people authored Jun 26, 2024
1 parent 86412cb commit 0ca7df7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/generated/packages/next/executors/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
"experimentalAppOnly": {
"type": "boolean",
"description": "Only build 'app' routes"
},
"experimentalBuildMode": {
"type": "string",
"description": "Change the build mode.",
"enum": ["compile", "generate"]
}
},
"required": ["outputPath"],
Expand Down
15 changes: 13 additions & 2 deletions packages/next/src/executors/build/build.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,24 @@ function runCliBuild(
projectRoot: string,
options: NextBuildBuilderOptions
) {
const { experimentalAppOnly, profile, debug, outputPath } = options;
const {
experimentalAppOnly,
experimentalBuildMode,
profile,
debug,
outputPath,
} = options;

// Set output path here since it can also be set via CLI
// We can retrieve it inside plugins/with-nx
process.env.NX_NEXT_OUTPUT_PATH ??= outputPath;

const args = createCliOptions({ experimentalAppOnly, profile, debug });
const args = createCliOptions({
experimentalAppOnly,
experimentalBuildMode,
profile,
debug,
});
return new Promise((resolve, reject) => {
childProcess = fork(
require.resolve('next/dist/bin/next'),
Expand Down
5 changes: 5 additions & 0 deletions packages/next/src/executors/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
"experimentalAppOnly": {
"type": "boolean",
"description": "Only build 'app' routes"
},
"experimentalBuildMode": {
"type": "string",
"description": "Change the build mode.",
"enum": ["compile", "generate"]
}
},
"required": ["outputPath"],
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface NextBuildBuilderOptions {
debug?: boolean;
profile?: boolean;
experimentalAppOnly?: boolean;
experimentalBuildMode?: 'compile' | 'generate';
}

export interface NextServeBuilderOptions {
Expand Down

0 comments on commit 0ca7df7

Please sign in to comment.