Skip to content

Commit

Permalink
Run server client/server builds serially (#23371)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ijjk authored Mar 24, 2021
1 parent 9821140 commit a6c0d76
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
38 changes: 22 additions & 16 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions packages/next/next-server/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const defaultConfig: NextConfig = {
scriptLoader: false,
stats: false,
externalDir: false,
serialWebpackBuild: false,
},
future: {
strictPostcssConfiguration: false,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit a6c0d76

Please sign in to comment.