From a6c0d76ebb72a1d7ad2d93b5f78bc0e1856bc092 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 24 Mar 2021 15:50:49 -0500 Subject: [PATCH] Run server client/server builds serially (#23371) Previously we special cased serverless builds and ran the client/server builds serially to allow the server build to load manifests produced in the client. To help with memory usage and for consistency this updates server mode to build in the same way. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. ## Documentation / Examples - [ ] Make sure the linting passes --- packages/next/build/index.ts | 38 +++++++++++-------- .../next/next-server/server/config-shared.ts | 1 + yarn.lock | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 1dfcc11c75300..f7b50fbe34656 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -511,22 +511,28 @@ export default async function build( const webpackBuildStart = process.hrtime() let result: CompilerResult = { warnings: [], errors: [] } - // TODO: why do we need this?? https://github.com/vercel/next.js/issues/8253 - if (isLikeServerless) { - const clientResult = await runCompiler(clientConfig) - // Fail build if clientResult contains errors - if (clientResult.errors.length > 0) { - result = { - warnings: [...clientResult.warnings], - errors: [...clientResult.errors], - } - } else { - const serverResult = await runCompiler(configs[1]) - result = { - warnings: [...clientResult.warnings, ...serverResult.warnings], - errors: [...clientResult.errors, ...serverResult.errors], - } - } + // We run client and server compilation separately when configured for + // memory constraint and for serverless to be able to load manifests + // produced in the client build + if (isLikeServerless || config.experimental.serialWebpackBuild) { + await nextBuildSpan + .traceChild('run-webpack-compiler') + .traceAsyncFn(async () => { + const clientResult = await runCompiler(clientConfig) + // Fail build if clientResult contains errors + if (clientResult.errors.length > 0) { + result = { + warnings: [...clientResult.warnings], + errors: [...clientResult.errors], + } + } else { + const serverResult = await runCompiler(configs[1]) + result = { + warnings: [...clientResult.warnings, ...serverResult.warnings], + errors: [...clientResult.errors, ...serverResult.errors], + } + } + }) } else { result = await nextBuildSpan .traceChild('run-webpack-compiler') diff --git a/packages/next/next-server/server/config-shared.ts b/packages/next/next-server/server/config-shared.ts index 196973e5709bb..a7776ce1d1b4b 100644 --- a/packages/next/next-server/server/config-shared.ts +++ b/packages/next/next-server/server/config-shared.ts @@ -80,6 +80,7 @@ export const defaultConfig: NextConfig = { scriptLoader: false, stats: false, externalDir: false, + serialWebpackBuild: false, }, future: { strictPostcssConfiguration: false, diff --git a/yarn.lock b/yarn.lock index 9e6c1dd9cd922..f38329f61bf22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4730,7 +4730,7 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001165, caniuse-lite@^1.0.30001173, caniuse-lite@^1.0.30001179: +caniuse-lite@1.0.30001179, caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, caniuse-lite@^1.0.30001093, caniuse-lite@^1.0.30001165, caniuse-lite@^1.0.30001173, caniuse-lite@^1.0.30001179: version "1.0.30001179" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001179.tgz#b0803883b4471a6c62066fb1752756f8afc699c8" integrity sha512-blMmO0QQujuUWZKyVrD1msR4WNDAqb/UPO1Sw2WWsQ7deoM5bJiicKnWJ1Y0NS/aGINSnKPIWBMw5luX+NDUCA==