File tree 3 files changed +33
-38
lines changed
3 files changed +33
-38
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
30
30
arraify ,
31
31
asyncFlatten ,
32
32
copyDir ,
33
+ displayTime ,
33
34
emptyDir ,
34
35
joinUrlSegments ,
35
36
normalizePath ,
@@ -559,6 +560,7 @@ export async function build(
559
560
}
560
561
561
562
let bundle : RollupBuild | undefined
563
+ let startTime : number | undefined
562
564
try {
563
565
const buildOutputOptions = ( output : OutputOptions = { } ) : OutputOptions => {
564
566
// @ts -expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
@@ -692,6 +694,7 @@ export async function build(
692
694
693
695
// write or generate files with rollup
694
696
const { rollup } = await import ( 'rollup' )
697
+ startTime = Date . now ( )
695
698
bundle = await rollup ( rollupOptions )
696
699
697
700
if ( options . write ) {
@@ -702,10 +705,19 @@ export async function build(
702
705
for ( const output of normalizedOutputs ) {
703
706
res . push ( await bundle [ options . write ? 'write' : 'generate' ] ( output ) )
704
707
}
708
+ config . logger . info (
709
+ `${ colors . green ( `✓ built in ${ displayTime ( Date . now ( ) - startTime ) } ` ) } ` ,
710
+ )
705
711
return Array . isArray ( outputs ) ? res : res [ 0 ]
706
712
} catch ( e ) {
707
713
e . message = mergeRollupError ( e )
708
714
clearLine ( )
715
+ if ( startTime ) {
716
+ config . logger . error (
717
+ `${ colors . red ( 'x' ) } Build failed in ${ displayTime ( Date . now ( ) - startTime ) } ` ,
718
+ )
719
+ startTime = undefined
720
+ }
709
721
throw e
710
722
} finally {
711
723
if ( bundle ) await bundle . close ( )
Original file line number Diff line number Diff line change @@ -47,8 +47,6 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
47
47
let transformedCount = 0
48
48
let chunkCount = 0
49
49
let compressedCount = 0
50
- let startTime = Date . now ( )
51
- let buildFailed = false
52
50
53
51
async function getCompressedSize (
54
52
code : string | Uint8Array ,
@@ -101,16 +99,11 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
101
99
return null
102
100
} ,
103
101
104
- options ( ) {
105
- startTime = Date . now ( )
106
- } ,
107
-
108
102
buildStart ( ) {
109
103
transformedCount = 0
110
104
} ,
111
105
112
- buildEnd ( error ?: Error ) {
113
- buildFailed = ! ! error
106
+ buildEnd ( ) {
114
107
if ( shouldLogInfo ) {
115
108
if ( tty ) {
116
109
clearLine ( )
@@ -301,16 +294,6 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
301
294
)
302
295
}
303
296
} ,
304
-
305
- closeBundle ( ) {
306
- if ( shouldLogInfo && ! config . build . watch && ! buildFailed ) {
307
- config . logger . info (
308
- `${ colors . green (
309
- `✓ built in ${ displayTime ( Date . now ( ) - startTime ) } ` ,
310
- ) } `,
311
- )
312
- }
313
- } ,
314
297
}
315
298
}
316
299
@@ -338,23 +321,3 @@ function throttle(fn: Function) {
338
321
} , 100 )
339
322
}
340
323
}
341
-
342
- function displayTime ( time : number ) {
343
- // display: {X}ms
344
- if ( time < 1000 ) {
345
- return `${ time } ms`
346
- }
347
-
348
- time = time / 1000
349
-
350
- // display: {X}s
351
- if ( time < 60 ) {
352
- return `${ time . toFixed ( 2 ) } s`
353
- }
354
-
355
- const mins = parseInt ( ( time / 60 ) . toString ( ) )
356
- const seconds = time % 60
357
-
358
- // display: {X}m {Y}s
359
- return `${ mins } m${ seconds < 1 ? '' : ` ${ seconds . toFixed ( 0 ) } s` } `
360
- }
Original file line number Diff line number Diff line change @@ -1426,3 +1426,23 @@ export function sortObjectKeys<T extends Record<string, any>>(obj: T): T {
1426
1426
}
1427
1427
return sorted as T
1428
1428
}
1429
+
1430
+ export function displayTime ( time : number ) : string {
1431
+ // display: {X}ms
1432
+ if ( time < 1000 ) {
1433
+ return `${ time } ms`
1434
+ }
1435
+
1436
+ time = time / 1000
1437
+
1438
+ // display: {X}s
1439
+ if ( time < 60 ) {
1440
+ return `${ time . toFixed ( 2 ) } s`
1441
+ }
1442
+
1443
+ const mins = parseInt ( ( time / 60 ) . toString ( ) )
1444
+ const seconds = time % 60
1445
+
1446
+ // display: {X}m {Y}s
1447
+ return `${ mins } m${ seconds < 1 ? '' : ` ${ seconds . toFixed ( 0 ) } s` } `
1448
+ }
You can’t perform that action at this time.
0 commit comments