@@ -330,8 +330,9 @@ class Stats {
330330 obj . modules . sort ( sortByField ( sortModules ) ) ;
331331 }
332332 if ( showChildren ) {
333- obj . children = compilation . children . map ( child => {
334- const obj = new Stats ( child ) . toJson ( options , forToString ) ;
333+ obj . children = compilation . children . map ( ( child , idx ) => {
334+ const childOptions = Stats . getChildOptions ( options , idx ) ;
335+ const obj = new Stats ( child ) . toJson ( childOptions , forToString ) ;
335336 delete obj . hash ;
336337 delete obj . version ;
337338 obj . name = child . name ;
@@ -766,17 +767,20 @@ class Stats {
766767 }
767768 if ( obj . children ) {
768769 obj . children . forEach ( child => {
769- if ( child . name ) {
770- colors . normal ( "Child " ) ;
771- colors . bold ( child . name ) ;
772- colors . normal ( ":" ) ;
773- } else {
774- colors . normal ( "Child" ) ;
770+ let childString = Stats . jsonToString ( child , useColors ) ;
771+ if ( childString ) {
772+ if ( child . name ) {
773+ colors . normal ( "Child " ) ;
774+ colors . bold ( child . name ) ;
775+ colors . normal ( ":" ) ;
776+ } else {
777+ colors . normal ( "Child" ) ;
778+ }
779+ newline ( ) ;
780+ buf . push ( " " ) ;
781+ buf . push ( childString . replace ( / \n / g, "\n " ) ) ;
782+ newline ( ) ;
775783 }
776- newline ( ) ;
777- buf . push ( " " ) ;
778- buf . push ( Stats . jsonToString ( child , useColors ) . replace ( / \n / g, "\n " ) ) ;
779- newline ( ) ;
780784 } ) ;
781785 }
782786 if ( obj . needAdditionalPass ) {
@@ -834,6 +838,24 @@ class Stats {
834838 }
835839
836840 }
841+
842+ static getChildOptions ( options , idx ) {
843+ let innerOptions ;
844+ if ( Array . isArray ( options . children ) ) {
845+ if ( idx < options . children . length )
846+ innerOptions = options . children [ idx ] ;
847+ } else if ( typeof options . children === "object" && options . children ) {
848+ innerOptions = options . children ;
849+ }
850+ if ( typeof innerOptions === "boolean" || typeof innerOptions === "string" )
851+ innerOptions = Stats . presetToOptions ( innerOptions ) ;
852+ if ( ! innerOptions )
853+ return options ;
854+ let childOptions = Object . assign ( { } , options ) ;
855+ delete childOptions . children ; // do not inherit children
856+ childOptions = Object . assign ( childOptions , innerOptions ) ;
857+ return childOptions ;
858+ }
837859}
838860
839861module . exports = Stats ;
0 commit comments