@@ -223,7 +223,7 @@ export function buildWebpackBrowser(
223223 const host = new NodeJsSyncHost ( ) ;
224224 const root = normalize ( context . workspaceRoot ) ;
225225
226- const projectName = context . target && context . target . project ;
226+ const projectName = context . target ? .project ;
227227 if ( ! projectName ) {
228228 throw new Error ( 'The builder requires a target.' ) ;
229229 }
@@ -596,9 +596,9 @@ export function buildWebpackBrowser(
596596 {
597597 size : bundle . size ,
598598 files : bundle . map ? [ bundle . filename , bundle . map . filename ] : [ bundle . filename ] ,
599- names : chunk && chunk . names ,
600- entry : ! ! chunk && chunk . names . includes ( 'runtime' ) ,
601- initial : ! ! chunk && chunk . initial ,
599+ names : chunk ? .names ,
600+ entry : ! ! chunk ? .names . includes ( 'runtime' ) ,
601+ initial : ! ! chunk ? .initial ,
602602 rendered : true ,
603603 } ,
604604 true ,
@@ -607,8 +607,7 @@ export function buildWebpackBrowser(
607607
608608 const bundleInfoStats : BundleStats [ ] = [ ] ;
609609 for ( const result of processResults ) {
610- const chunk = webpackStats . chunks
611- && webpackStats . chunks . find ( ( chunk ) => chunk . id . toString ( ) === result . name ) ;
610+ const chunk = webpackStats . chunks ?. find ( ( chunk ) => chunk . id . toString ( ) === result . name ) ;
612611
613612 if ( result . original ) {
614613 bundleInfoStats . push ( generateBundleInfoStats ( result . original , chunk ) ) ;
@@ -619,22 +618,20 @@ export function buildWebpackBrowser(
619618 }
620619 }
621620
622- const unprocessedChunks = webpackStats . chunks && webpackStats . chunks
623- . filter ( ( chunk ) => ! processResults
624- . find ( ( result ) => chunk . id . toString ( ) === result . name ) ,
625- ) || [ ] ;
621+ const unprocessedChunks = webpackStats . chunks ?. filter ( ( chunk ) => ! processResults
622+ . find ( ( result ) => chunk . id . toString ( ) === result . name ) ,
623+ ) || [ ] ;
626624 for ( const chunk of unprocessedChunks ) {
627- const asset =
628- webpackStats . assets && webpackStats . assets . find ( a => a . name === chunk . files [ 0 ] ) ;
629- bundleInfoStats . push ( generateBundleStats ( { ...chunk , size : asset && asset . size } , true ) ) ;
625+ const asset = webpackStats . assets ?. find ( a => a . name === chunk . files [ 0 ] ) ;
626+ bundleInfoStats . push ( generateBundleStats ( { ...chunk , size : asset ?. size } , true ) ) ;
630627 }
631628
632629 context . logger . info (
633630 '\n' +
634631 generateBuildStatsTable ( bundleInfoStats , colors . enabled ) +
635632 '\n\n' +
636633 generateBuildStats (
637- ( webpackStats && webpackStats . hash ) || '<unknown>' ,
634+ webpackStats ? .hash || '<unknown>' ,
638635 Date . now ( ) - startTime ,
639636 true ,
640637 ) ,
@@ -706,17 +703,17 @@ export function buildWebpackBrowser(
706703 }
707704 }
708705
709- if ( options . index ) {
710- for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
711- let localeBaseHref ;
712- if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
713- localeBaseHref = urlJoin (
714- options . baseHref || '' ,
715- i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
716- ) ;
717- }
706+ for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
707+ let localeBaseHref ;
708+ if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
709+ localeBaseHref = urlJoin (
710+ options . baseHref || '' ,
711+ i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
712+ ) ;
713+ }
718714
719- try {
715+ try {
716+ if ( options . index ) {
720717 await generateIndex (
721718 outputPath ,
722719 options ,
@@ -729,23 +726,9 @@ export function buildWebpackBrowser(
729726 locale || options . i18nLocale ,
730727 localeBaseHref || options . baseHref ,
731728 ) ;
732- } catch ( err ) {
733- return { success : false , error : mapErrorToMessage ( err ) } ;
734729 }
735- }
736- }
737730
738- if ( options . serviceWorker ) {
739- for ( const [ locale , outputPath ] of outputPaths . entries ( ) ) {
740- let localeBaseHref ;
741- if ( i18n . locales [ locale ] && i18n . locales [ locale ] . baseHref !== '' ) {
742- localeBaseHref = urlJoin (
743- options . baseHref || '' ,
744- i18n . locales [ locale ] . baseHref ?? `/${ locale } /` ,
745- ) ;
746- }
747-
748- try {
731+ if ( options . serviceWorker ) {
749732 await augmentAppWithServiceWorker (
750733 host ,
751734 root ,
@@ -754,9 +737,9 @@ export function buildWebpackBrowser(
754737 localeBaseHref || options . baseHref || '/' ,
755738 options . ngswConfigPath ,
756739 ) ;
757- } catch ( err ) {
758- return { success : false , error : mapErrorToMessage ( err ) } ;
759740 }
741+ } catch ( err ) {
742+ return { success : false , error : mapErrorToMessage ( err ) } ;
760743 }
761744 }
762745 }
0 commit comments