@@ -365,45 +365,51 @@ export function getServerAddresses(port: number, host: string, proto: string) {
365365
366366export async function storybookDevServer ( options : any ) {
367367 const app = express ( ) ;
368- const server = await getServer ( app , options ) ;
369368
370369 const configDir = path . resolve ( options . configDir ) ;
371370 const outputDir = options . smokeTest
372371 ? resolvePathInStorybookCache ( 'public' )
373372 : path . resolve ( options . outputDir || resolvePathInStorybookCache ( 'public' ) ) ;
374373 const configType = 'DEVELOPMENT' ;
375374 const startTime = process . hrtime ( ) ;
375+ const prebuiltDir = await getPrebuiltDir ( { configDir, options } ) ;
376+ let address ;
377+ let networkAddress ;
376378
377- if ( typeof options . extendServer === 'function' ) {
378- options . extendServer ( server ) ;
379- }
379+ if ( ! options . buildOnly ) {
380+ const server = await getServer ( app , options ) ;
380381
381- app . use ( ( req , res , next ) => {
382- res . header ( 'Access-Control-Allow-Origin' , '*' ) ;
383- res . header ( 'Access-Control-Allow-Headers' , 'Origin, X-Requested-With, Content-Type, Accept' ) ;
384- next ( ) ;
385- } ) ;
382+ if ( typeof options . extendServer === 'function' ) {
383+ options . extendServer ( server ) ;
384+ }
386385
387- // User's own static files
388- await useStatics ( router , options ) ;
386+ app . use ( ( req , res , next ) => {
387+ res . header ( 'Access-Control-Allow-Origin' , '*' ) ;
388+ res . header ( 'Access-Control-Allow-Headers' , 'Origin, X-Requested-With, Content-Type, Accept' ) ;
389+ next ( ) ;
390+ } ) ;
389391
390- getMiddleware ( configDir ) ( router ) ;
391- app . use ( router ) ;
392+ // User's own static files
393+ await useStatics ( router , options ) ;
392394
393- const { port, host } = options ;
394- const proto = options . https ? 'https' : 'http' ;
395- const { address, networkAddress } = getServerAddresses ( port , host , proto ) ;
395+ getMiddleware ( configDir ) ( router ) ;
396+ app . use ( router ) ;
396397
397- await new Promise ( ( resolve , reject ) => {
398- // FIXME: Following line doesn't match TypeScript signature at all 🤔
399- // @ts -ignore
400- server . listen ( { port , host } , ( error : Error ) => ( error ? reject ( error ) : resolve ( ) ) ) ;
401- } ) ;
398+ const { port , host } = options ;
399+ const proto = options . https ? 'https' : 'http' ;
400+ const serverAddresses = getServerAddresses ( port , host , proto ) ;
401+ networkAddress = serverAddresses . networkAddress ;
402+ address = serverAddresses . address ;
402403
403- const prebuiltDir = await getPrebuiltDir ( { configDir, options } ) ;
404+ await new Promise ( ( resolve , reject ) => {
405+ // FIXME: Following line doesn't match TypeScript signature at all 🤔
406+ // @ts -ignore
407+ server . listen ( { port, host } , ( error : Error ) => ( error ? reject ( error ) : resolve ( ) ) ) ;
408+ } ) ;
404409
405- // Manager static files
406- router . use ( '/' , express . static ( prebuiltDir || outputDir ) ) ;
410+ // Manager static files
411+ router . use ( '/' , express . static ( prebuiltDir || outputDir ) ) ;
412+ }
407413
408414 // Build the manager and preview in parallel.
409415 // Start the server (and open the browser) as soon as the manager is ready.
@@ -413,14 +419,14 @@ export async function storybookDevServer(options: any) {
413419 startManager ( { startTime, options, configType, outputDir, configDir, prebuiltDir } )
414420 // TODO #13083 Restore this when compiling the preview is fast enough
415421 // .then((result) => {
416- // if (!options.ci && !options.smokeTest) openInBrowser(address);
422+ // if (!options.ci && !options.smokeTest && !options.buildOnly ) openInBrowser(address);
417423 // return result;
418424 // })
419425 . catch ( bailPreview ) ,
420426 ] ) ;
421427
422428 // TODO #13083 Remove this when compiling the preview is fast enough
423- if ( ! options . ci && ! options . smokeTest ) openInBrowser ( networkAddress ) ;
429+ if ( ! options . ci && ! options . smokeTest && ! options . buildOnly ) openInBrowser ( networkAddress ) ;
424430
425431 return { ...previewResult , ...managerResult , address, networkAddress } ;
426432}
0 commit comments