@@ -78,7 +78,18 @@ class Stats {
7878
7979 const optionOrLocalFallback = ( v , def ) =>
8080 typeof v !== "undefined" ? v :
81- typeof options . all !== "undefined" ? options . all : def ;
81+ typeof options . all !== "undefined" ? options . all : def ;
82+
83+ const testAgainstGivenOption = ( item ) => {
84+ if ( typeof item === "string" ) {
85+ const regExp = new RegExp ( `[\\\\/]${ item . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, "\\$&" ) } ([\\\\/]|$|!|\\?)` ) ; // eslint-disable-line no-useless-escape
86+ return ident => regExp . test ( ident ) ;
87+ }
88+ if ( item && typeof item === "object" && typeof item . test === "function" )
89+ return ident => item . test ( ident ) ;
90+ if ( typeof item === "function" )
91+ return item ;
92+ } ;
8293
8394 const compilation = this . compilation ;
8495 const context = optionOrFallback ( options . context , process . cwd ( ) ) ;
@@ -108,16 +119,8 @@ class Stats {
108119 const showWarnings = optionOrLocalFallback ( options . warnings , true ) ;
109120 const warningsFilter = optionOrFallback ( options . warningsFilter , null ) ;
110121 const showPublicPath = optionOrLocalFallback ( options . publicPath , ! forToString ) ;
111- const excludeModules = [ ] . concat ( optionOrFallback ( options . exclude , [ ] ) ) . map ( item => {
112- if ( typeof item === "string" ) {
113- const regExp = new RegExp ( `[\\\\/]${ item . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, "\\$&" ) } ([\\\\/]|$|!|\\?)` ) ; // eslint-disable-line no-useless-escape
114- return ident => regExp . test ( ident ) ;
115- }
116- if ( item && typeof item === "object" && typeof item . test === "function" )
117- return ident => item . test ( ident ) ;
118- if ( typeof item === "function" )
119- return item ;
120- } ) ;
122+ const excludeModules = [ ] . concat ( optionOrFallback ( options . exclude , [ ] ) ) . map ( testAgainstGivenOption ) ;
123+ const excludeAssets = [ ] . concat ( optionOrFallback ( options . excludeAssets , [ ] ) ) . map ( testAgainstGivenOption ) ;
121124 const maxModules = optionOrFallback ( options . maxModules , forToString ? 15 : Infinity ) ;
122125 const sortModules = optionOrFallback ( options . modulesSort , "id" ) ;
123126 const sortChunks = optionOrFallback ( options . chunksSort , "id" ) ;
@@ -140,6 +143,18 @@ class Stats {
140143 } ;
141144 } ;
142145
146+ const createAssetFilter = ( ) => {
147+ return asset => {
148+ if ( excludeAssets . length > 0 ) {
149+ const ident = asset . name ;
150+ const excluded = excludeAssets . some ( fn => fn ( ident , asset ) ) ;
151+ if ( excluded )
152+ return false ;
153+ }
154+ return showCachedAssets || asset . emitted ;
155+ } ;
156+ } ;
157+
143158 const sortByFieldAndOrder = ( fieldKey , a , b ) => {
144159 if ( a [ fieldKey ] === null && b [ fieldKey ] === null ) return 0 ;
145160 if ( a [ fieldKey ] === null ) return 1 ;
@@ -247,7 +262,7 @@ class Stats {
247262
248263 assetsByFile [ asset ] = obj ;
249264 return obj ;
250- } ) . filter ( asset => showCachedAssets || asset . emitted ) ;
265+ } ) . filter ( createAssetFilter ( ) ) ;
251266
252267 compilation . chunks . forEach ( chunk => {
253268 chunk . files . forEach ( asset => {
@@ -433,7 +448,7 @@ class Stats {
433448 if ( useColors ) {
434449 buf . push (
435450 ( useColors === true || useColors [ color ] === undefined ) ?
436- defaultColors [ color ] : useColors [ color ]
451+ defaultColors [ color ] : useColors [ color ]
437452 ) ;
438453 }
439454 buf . push ( str ) ;
@@ -443,8 +458,8 @@ class Stats {
443458 } ;
444459 return obj ;
445460 } , {
446- normal : ( str ) => buf . push ( str )
447- } ) ;
461+ normal : ( str ) => buf . push ( str )
462+ } ) ;
448463
449464 const coloredTime = ( time ) => {
450465 let times = [ 800 , 400 , 200 , 100 ] ;
0 commit comments