File tree Expand file tree Collapse file tree 3 files changed +33
-38
lines changed Expand file tree Collapse file tree 3 files changed +33
-38
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
3030 arraify ,
3131 asyncFlatten ,
3232 copyDir ,
33+ displayTime ,
3334 emptyDir ,
3435 joinUrlSegments ,
3536 normalizePath ,
@@ -559,6 +560,7 @@ export async function build(
559560 }
560561
561562 let bundle : RollupBuild | undefined
563+ let startTime : number | undefined
562564 try {
563565 const buildOutputOptions = ( output : OutputOptions = { } ) : OutputOptions => {
564566 // @ts -expect-error See https://github.com/vitejs/vite/issues/5812#issuecomment-984345618
@@ -692,6 +694,7 @@ export async function build(
692694
693695 // write or generate files with rollup
694696 const { rollup } = await import ( 'rollup' )
697+ startTime = Date . now ( )
695698 bundle = await rollup ( rollupOptions )
696699
697700 if ( options . write ) {
@@ -702,10 +705,19 @@ export async function build(
702705 for ( const output of normalizedOutputs ) {
703706 res . push ( await bundle [ options . write ? 'write' : 'generate' ] ( output ) )
704707 }
708+ config . logger . info (
709+ `${ colors . green ( `✓ built in ${ displayTime ( Date . now ( ) - startTime ) } ` ) } ` ,
710+ )
705711 return Array . isArray ( outputs ) ? res : res [ 0 ]
706712 } catch ( e ) {
707713 e . message = mergeRollupError ( e )
708714 clearLine ( )
715+ if ( startTime ) {
716+ config . logger . error (
717+ `${ colors . red ( 'x' ) } Build failed in ${ displayTime ( Date . now ( ) - startTime ) } ` ,
718+ )
719+ startTime = undefined
720+ }
709721 throw e
710722 } finally {
711723 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 {
4747 let transformedCount = 0
4848 let chunkCount = 0
4949 let compressedCount = 0
50- let startTime = Date . now ( )
51- let buildFailed = false
5250
5351 async function getCompressedSize (
5452 code : string | Uint8Array ,
@@ -101,16 +99,11 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
10199 return null
102100 } ,
103101
104- options ( ) {
105- startTime = Date . now ( )
106- } ,
107-
108102 buildStart ( ) {
109103 transformedCount = 0
110104 } ,
111105
112- buildEnd ( error ?: Error ) {
113- buildFailed = ! ! error
106+ buildEnd ( ) {
114107 if ( shouldLogInfo ) {
115108 if ( tty ) {
116109 clearLine ( )
@@ -301,16 +294,6 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin {
301294 )
302295 }
303296 } ,
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- } ,
314297 }
315298}
316299
@@ -338,23 +321,3 @@ function throttle(fn: Function) {
338321 } , 100 )
339322 }
340323}
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 {
14261426 }
14271427 return sorted as T
14281428}
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