@@ -2390,15 +2390,8 @@ class WebpackCLI {
23902390 ) ?. devServerOptions . devMiddleware ?. stats ;
23912391
23922392 if ( typeof middlewareStats !== "undefined" ) {
2393- const { colors } = configuration . stats as StatsOptions ;
2394-
2395- configuration . stats =
2396- typeof middlewareStats === "boolean"
2397- ? { preset : middlewareStats ? "normal" : "none" }
2398- : typeof middlewareStats === "string"
2399- ? { preset : middlewareStats }
2400- : { ...middlewareStats } ;
2401- configuration . stats . colors ??= colors ;
2393+ configuration . stats = middlewareStats ;
2394+ this . #setupStats( configuration ) ;
24022395 }
24032396 }
24042397
@@ -3781,33 +3774,7 @@ class WebpackCLI {
37813774 configuration . mode = process . env . NODE_ENV ;
37823775 }
37833776
3784- // Setup stats
3785- if ( typeof configuration . stats === "undefined" ) {
3786- configuration . stats = { preset : "normal" } ;
3787- } else if ( typeof configuration . stats === "boolean" ) {
3788- configuration . stats = configuration . stats ? { preset : "normal" } : { preset : "none" } ;
3789- } else if ( typeof configuration . stats === "string" ) {
3790- configuration . stats = { preset : configuration . stats } ;
3791- }
3792-
3793- let colors ;
3794-
3795- // From arguments
3796- if ( typeof this . #isColorSupportChanged !== "undefined" ) {
3797- colors = Boolean ( this . #isColorSupportChanged) ;
3798- }
3799- // From stats
3800- else if ( typeof configuration . stats . colors !== "undefined" ) {
3801- colors = configuration . stats . colors ;
3802- }
3803- // Default
3804- else {
3805- colors = Boolean ( this . colors . isColorSupported ) ;
3806- }
3807-
3808- if ( Object . isExtensible ( configuration . stats ) ) {
3809- configuration . stats . colors = colors ;
3810- }
3777+ this . #setupStats( configuration ) ;
38113778
38123779 // Apply CLI plugin
38133780 if ( ! configuration . plugins ) {
@@ -3838,6 +3805,35 @@ class WebpackCLI {
38383805 return config ;
38393806 }
38403807
3808+ #setupStats( configuration : Configuration ) : void {
3809+ if ( typeof configuration . stats === "undefined" ) {
3810+ configuration . stats = { preset : "normal" } ;
3811+ } else if ( typeof configuration . stats === "boolean" ) {
3812+ configuration . stats = configuration . stats ? { preset : "normal" } : { preset : "none" } ;
3813+ } else if ( typeof configuration . stats === "string" ) {
3814+ configuration . stats = { preset : configuration . stats } ;
3815+ }
3816+
3817+ let colors ;
3818+
3819+ // From arguments
3820+ if ( typeof this . #isColorSupportChanged !== "undefined" ) {
3821+ colors = Boolean ( this . #isColorSupportChanged) ;
3822+ }
3823+ // From stats
3824+ else if ( typeof configuration . stats . colors !== "undefined" ) {
3825+ colors = configuration . stats . colors ;
3826+ }
3827+ // Default
3828+ else {
3829+ colors = Boolean ( this . colors . isColorSupported ) ;
3830+ }
3831+
3832+ if ( Object . isExtensible ( configuration . stats ) ) {
3833+ configuration . stats . colors = colors ;
3834+ }
3835+ }
3836+
38413837 async createCompiler (
38423838 options : Options ,
38433839 callback ?: WebpackCallback ,
0 commit comments