@@ -176,111 +176,123 @@ cli
176176 `[boolean] force the optimizer to ignore the cache and re-bundle` ,
177177 )
178178 // TODO(underfin): Consider how to merge the build option into dev command.
179- . action ( async ( root : string , options : BuildEnvironmentOptions & BuilderCLIOptions & ServerOptions & GlobalCLIOptions ) => {
180- filterDuplicateOptions ( options )
181- // output structure is preserved even after bundling so require()
182- // is ok here
183- const { createServer } = await import ( './server' )
184- try {
185- const server = await createServer ( {
186- root,
187- base : options . base ,
188- mode : options . mode ,
189- configFile : options . config ,
190- configLoader : options . configLoader ,
191- logLevel : options . logLevel ,
192- clearScreen : options . clearScreen ,
193- server : cleanGlobalCLIOptions ( options ) ,
194- forceOptimizeDeps : options . force ,
195- } )
179+ . action (
180+ async (
181+ root : string ,
182+ options : BuildEnvironmentOptions &
183+ BuilderCLIOptions &
184+ ServerOptions &
185+ GlobalCLIOptions ,
186+ ) => {
187+ filterDuplicateOptions ( options )
188+ // output structure is preserved even after bundling so require()
189+ // is ok here
190+ const { createServer } = await import ( './server' )
191+ try {
192+ const server = await createServer ( {
193+ root,
194+ base : options . base ,
195+ mode : options . mode ,
196+ configFile : options . config ,
197+ configLoader : options . configLoader ,
198+ logLevel : options . logLevel ,
199+ clearScreen : options . clearScreen ,
200+ server : cleanGlobalCLIOptions ( options ) ,
201+ forceOptimizeDeps : options . force ,
202+ } )
196203
197- if ( ! server . httpServer ) {
198- throw new Error ( 'HTTP server not available' )
199- }
204+ if ( ! server . httpServer ) {
205+ throw new Error ( 'HTTP server not available' )
206+ }
200207
201- const { createBuilder } = await import ( './build' )
208+ const { createBuilder } = await import ( './build' )
202209
203- const buildOptions : BuildEnvironmentOptions = cleanBuilderCLIOptions ( options )
210+ const buildOptions : BuildEnvironmentOptions =
211+ cleanBuilderCLIOptions ( options )
204212
205- const inlineConfig : InlineConfig = {
206- root,
207- base : options . base ,
208- mode : options . mode ,
209- configFile : options . config ,
210- configLoader : options . configLoader ,
211- logLevel : options . logLevel ,
212- clearScreen : options . clearScreen ,
213- build : buildOptions ,
214- ...( options . app ? { builder : { } } : { } ) ,
215- }
216- const builder = await createBuilder ( inlineConfig , null , 'serve' )
217- await builder . buildApp ( server )
213+ const inlineConfig : InlineConfig = {
214+ root,
215+ base : options . base ,
216+ mode : options . mode ,
217+ configFile : options . config ,
218+ configLoader : options . configLoader ,
219+ logLevel : options . logLevel ,
220+ clearScreen : options . clearScreen ,
221+ build : buildOptions ,
222+ ...( options . app ? { builder : { } } : { } ) ,
223+ }
224+ const builder = await createBuilder ( inlineConfig , null , 'serve' )
225+ await builder . buildApp ( server )
218226
219- await server . listen ( )
227+ await server . listen ( )
220228
221- const info = server . config . logger . info
229+ const info = server . config . logger . info
222230
223- const modeString =
224- options . mode && options . mode !== 'development'
225- ? ` ${ colors . bgGreen ( ` ${ colors . bold ( options . mode ) } ` ) } `
231+ const modeString =
232+ options . mode && options . mode !== 'development'
233+ ? ` ${ colors . bgGreen ( ` ${ colors . bold ( options . mode ) } ` ) } `
234+ : ''
235+ const viteStartTime = global . __vite_start_time ?? false
236+ const startupDurationString = viteStartTime
237+ ? colors . dim (
238+ `ready in ${ colors . reset (
239+ colors . bold ( Math . ceil ( performance . now ( ) - viteStartTime ) ) ,
240+ ) } ms`,
241+ )
226242 : ''
227- const viteStartTime = global . __vite_start_time ?? false
228- const startupDurationString = viteStartTime
229- ? colors . dim (
230- `ready in ${ colors . reset (
231- colors . bold ( Math . ceil ( performance . now ( ) - viteStartTime ) ) ,
232- ) } ms`,
233- )
234- : ''
235- const hasExistingLogs =
236- process . stdout . bytesWritten > 0 || process . stderr . bytesWritten > 0
243+ const hasExistingLogs =
244+ process . stdout . bytesWritten > 0 || process . stderr . bytesWritten > 0
237245
238- info (
239- `\n ${ colors . green (
240- `${ colors . bold ( 'VITE' ) } v${ VERSION } ` ,
241- ) } ${ modeString } ${ startupDurationString } \n`,
242- {
243- clear : ! hasExistingLogs ,
244- } ,
245- )
246+ info (
247+ `\n ${ colors . green (
248+ `${ colors . bold ( 'VITE' ) } v${ VERSION } ` ,
249+ ) } ${ modeString } ${ startupDurationString } \n`,
250+ {
251+ clear : ! hasExistingLogs ,
252+ } ,
253+ )
246254
247- server . printUrls ( )
248- const customShortcuts : CLIShortcut < typeof server > [ ] = [ ]
249- if ( profileSession ) {
250- customShortcuts . push ( {
251- key : 'p' ,
252- description : 'start/stop the profiler' ,
253- async action ( server ) {
254- if ( profileSession ) {
255- await stopProfiler ( server . config . logger . info )
256- } else {
257- const inspector = await import ( 'node:inspector' ) . then (
258- ( r ) => r . default ,
259- )
260- await new Promise < void > ( ( res ) => {
261- profileSession = new inspector . Session ( )
262- profileSession . connect ( )
263- profileSession . post ( 'Profiler.enable' , ( ) => {
264- profileSession ! . post ( 'Profiler.start' , ( ) => {
265- server . config . logger . info ( 'Profiler started' )
266- res ( )
255+ server . printUrls ( )
256+ const customShortcuts : CLIShortcut < typeof server > [ ] = [ ]
257+ if ( profileSession ) {
258+ customShortcuts . push ( {
259+ key : 'p' ,
260+ description : 'start/stop the profiler' ,
261+ async action ( server ) {
262+ if ( profileSession ) {
263+ await stopProfiler ( server . config . logger . info )
264+ } else {
265+ const inspector = await import ( 'node:inspector' ) . then (
266+ ( r ) => r . default ,
267+ )
268+ await new Promise < void > ( ( res ) => {
269+ profileSession = new inspector . Session ( )
270+ profileSession . connect ( )
271+ profileSession . post ( 'Profiler.enable' , ( ) => {
272+ profileSession ! . post ( 'Profiler.start' , ( ) => {
273+ server . config . logger . info ( 'Profiler started' )
274+ res ( )
275+ } )
267276 } )
268277 } )
269- } )
270- }
278+ }
279+ } ,
280+ } )
281+ }
282+ server . bindCLIShortcuts ( { print : true , customShortcuts } )
283+ } catch ( e ) {
284+ const logger = createLogger ( options . logLevel )
285+ logger . error (
286+ colors . red ( `error when starting dev server:\n${ e . stack } ` ) ,
287+ {
288+ error : e ,
271289 } ,
272- } )
290+ )
291+ stopProfiler ( logger . info )
292+ process . exit ( 1 )
273293 }
274- server . bindCLIShortcuts ( { print : true , customShortcuts } )
275- } catch ( e ) {
276- const logger = createLogger ( options . logLevel )
277- logger . error ( colors . red ( `error when starting dev server:\n${ e . stack } ` ) , {
278- error : e ,
279- } )
280- stopProfiler ( logger . info )
281- process . exit ( 1 )
282- }
283- } )
294+ } ,
295+ )
284296
285297// build
286298cli
0 commit comments