Skip to content

Commit 15a9619

Browse files
authored
Webpack build: Add compiled in x seconds in missing places (#77751)
### What? Added duration of the webpack build in a few missing places. This was already added earlier but it seems we missed 2 cases where it logs `compiled successfully` but did not include a timing. E.g. shadcn-ui's apps/v4 did not show the webpack compile time. ### How? - Moved the `durationToString` function from `build/index.ts` to a dedicated file - Added duration information to successful compilation messages in webpack build - Updated log messages to show compilation time in appropriate units (ms, s, min) Fixes #
1 parent 06384d1 commit 15a9619

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function durationToString(compilerDuration: number) {
2+
let durationString
3+
if (compilerDuration > 120) {
4+
durationString = `${(compilerDuration / 60).toFixed(1)}min`
5+
} else if (compilerDuration > 40) {
6+
durationString = `${compilerDuration.toFixed(0)}s`
7+
} else if (compilerDuration > 2) {
8+
durationString = `${compilerDuration.toFixed(1)}s`
9+
} else {
10+
durationString = `${(compilerDuration * 1000).toFixed(0)}ms`
11+
}
12+
return durationString
13+
}

packages/next/src/build/index.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ import { turbopackBuild } from './turbopack-build'
209209
import { isPersistentCachingEnabled } from '../shared/lib/turbopack/utils'
210210
import { inlineStaticEnv } from '../lib/inline-static-env'
211211
import { populateStaticEnv } from '../lib/static-env'
212+
import { durationToString } from './duration-to-string'
212213

213214
type Fallback = null | boolean | string
214215

@@ -3725,17 +3726,3 @@ export default async function build(
37253726
}
37263727
}
37273728
}
3728-
3729-
function durationToString(compilerDuration: number) {
3730-
let durationString
3731-
if (compilerDuration > 120) {
3732-
durationString = `${(compilerDuration / 60).toFixed(1)}min`
3733-
} else if (compilerDuration > 40) {
3734-
durationString = `${compilerDuration.toFixed(0)}s`
3735-
} else if (compilerDuration > 2) {
3736-
durationString = `${compilerDuration.toFixed(1)}s`
3737-
} else {
3738-
durationString = `${(compilerDuration * 1000).toFixed(0)}ms`
3739-
}
3740-
return durationString
3741-
}

packages/next/src/build/webpack-build/impl.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type { UnwrapPromise } from '../../lib/coalesced-function'
4040

4141
import origDebug from 'next/dist/compiled/debug'
4242
import { Telemetry } from '../../telemetry/storage'
43+
import { durationToString } from '../duration-to-string'
4344

4445
const debug = origDebug('next:build:webpack-build')
4546

@@ -340,12 +341,15 @@ export async function webpackBuildImpl(
340341
err.code = 'WEBPACK_ERRORS'
341342
throw err
342343
} else {
344+
const duration = webpackBuildEnd[0]
345+
const durationString = durationToString(duration)
346+
343347
if (result.warnings.length > 0) {
344-
Log.warn('Compiled with warnings\n')
348+
Log.warn(`Compiled with warnings in ${durationString}\n`)
345349
console.warn(result.warnings.filter(Boolean).join('\n\n'))
346350
console.warn()
347351
} else if (!compilerName) {
348-
Log.event('Compiled successfully')
352+
Log.event(`Compiled successfully in ${durationString}`)
349353
}
350354

351355
return {

packages/next/src/build/webpack-build/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getParsedNodeOptionsWithoutInspect,
1212
} from '../../server/lib/utils'
1313
import { mergeUseCacheTrackers } from '../webpack/plugins/telemetry-plugin/use-cache-tracker-utils'
14+
import { durationToString } from '../duration-to-string'
1415

1516
const debug = origDebug('next:build:webpack-build')
1617

@@ -119,7 +120,8 @@ async function webpackBuildWithWorker(
119120
}
120121

121122
if (compilerNames.length === 3) {
122-
Log.event('Compiled successfully')
123+
const durationString = durationToString(combinedResult.duration)
124+
Log.event(`Compiled successfully in ${durationString}`)
123125
}
124126

125127
return combinedResult

0 commit comments

Comments
 (0)