@@ -3,7 +3,9 @@ import type { NuxtAnalyzeMeta } from '@nuxt/schema'
33import { promises as fsp } from 'node:fs'
44import process from 'node:process'
55
6+ import { intro , note , outro , taskLog } from '@clack/prompts'
67import { defineCommand } from 'citty'
8+ import { colors } from 'consola/utils'
79import { defu } from 'defu'
810import { H3 , lazyEventHandler } from 'h3-next'
911import { join , resolve } from 'pathe'
@@ -13,6 +15,7 @@ import { overrideEnv } from '../utils/env'
1315import { clearDir } from '../utils/fs'
1416import { loadKit } from '../utils/kit'
1517import { logger } from '../utils/logger'
18+ import { relativeToProcess } from '../utils/paths'
1619import { cwdArgs , dotEnvArgs , extendsArgs , legacyRootDirArgs , logLevelArgs } from './_shared'
1720
1821const indexHtml = `
@@ -65,6 +68,8 @@ export default defineCommand({
6568 const name = ctx . args . name || 'default'
6669 const slug = name . trim ( ) . replace ( / [ ^ \w - ] / g, '_' )
6770
71+ intro ( colors . cyan ( 'Analyzing bundle size...' ) )
72+
6873 const startTime = Date . now ( )
6974
7075 const { loadNuxt, buildNuxt } = await loadKit ( cwd )
@@ -105,8 +110,17 @@ export default defineCommand({
105110 filename : join ( analyzeDir , 'client.html' ) ,
106111 } )
107112
113+ const tasklog = taskLog ( {
114+ title : 'Building Nuxt with analysis enabled' ,
115+ retainLog : false ,
116+ limit : 1 ,
117+ } )
118+
119+ tasklog . message ( 'Clearing analyze directory...' )
108120 await clearDir ( analyzeDir )
121+ tasklog . message ( 'Building Nuxt...' )
109122 await buildNuxt ( nuxt )
123+ tasklog . success ( 'Build complete' )
110124
111125 const endTime = Date . now ( )
112126
@@ -121,14 +135,9 @@ export default defineCommand({
121135 }
122136
123137 await nuxt . callHook ( 'build:analyze:done' , meta )
124- await fsp . writeFile (
125- join ( analyzeDir , 'meta.json' ) ,
126- JSON . stringify ( meta , null , 2 ) ,
127- 'utf-8' ,
128- )
138+ await fsp . writeFile ( join ( analyzeDir , 'meta.json' ) , JSON . stringify ( meta , null , 2 ) , 'utf-8' )
129139
130- logger . info ( `Analyze results are available at: \`${ analyzeDir } \`` )
131- logger . warn ( 'Do not deploy analyze results! Use `nuxi build` before deploying.' )
140+ note ( `${ relativeToProcess ( analyzeDir ) } \n\nDo not deploy analyze results! Use ${ colors . cyan ( 'nuxt build' ) } before deploying.` , 'Build location' )
132141
133142 if ( ctx . args . serve !== false && ! process . env . CI ) {
134143 const app = new H3 ( )
@@ -139,13 +148,16 @@ export default defineCommand({
139148 return ( ) => new Response ( contents , opts )
140149 } )
141150
142- logger . info ( 'Starting stats server...' )
151+ logger . step ( 'Starting stats server...' )
143152
144153 app . use ( '/client' , serveFile ( join ( analyzeDir , 'client.html' ) ) )
145154 app . use ( '/nitro' , serveFile ( join ( analyzeDir , 'nitro.html' ) ) )
146155 app . use ( ( ) => new Response ( indexHtml , opts ) )
147156
148157 await serve ( app ) . serve ( )
149158 }
159+ else {
160+ outro ( '✨ Analysis build complete!' )
161+ }
150162 } ,
151163} )
0 commit comments