feat(nextjs): add experimental-build-mode option to support compile only (#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
https://github.com/vercel/next.js/discussions/46544 for a discussion.

---------

Co-authored-by: Emily Xiong <xiongemi@gmail.com>
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
This commit is contained in:
dfr-exnaton 2024-06-26 22:54:49 +02:00 committed by GitHub
parent 86412cb99a
commit 0ca7df7495
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View File

@ -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"],

View File

@ -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'),

View File

@ -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"],

View File

@ -39,6 +39,7 @@ export interface NextBuildBuilderOptions {
debug?: boolean;
profile?: boolean;
experimentalAppOnly?: boolean;
experimentalBuildMode?: 'compile' | 'generate';
}
export interface NextServeBuilderOptions {