@@ -37,9 +37,25 @@ Stats.prototype.toJson = function toJson(options, forToString) {
3737 var showChildren = d ( options . children , true ) ;
3838 var showSource = d ( options . source , ! forToString ) ;
3939 var showErrorDetails = d ( options . errorDetails , ! forToString ) ;
40+ var excludeModules = [ ] . concat ( d ( options . exclude , [ ] ) ) . map ( function ( str ) {
41+ if ( typeof str !== "string" ) return str ;
42+ return new RegExp ( "[\\\\/]" + str . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, "\\$&" ) + "([\\\\/]|$|!|\\?)" ) ;
43+ } ) ;
4044 var sortModules = d ( options . modulesSort , "id" ) ;
4145 var sortChunks = d ( options . chunksSort , "id" ) ;
4246 var sortAssets = d ( options . assetsSort , "" ) ;
47+
48+ function moduleFilter ( module ) {
49+ if ( ! showCachedModules && ! module . built ) {
50+ return false ;
51+ }
52+ if ( excludeModules . length === 0 )
53+ return true ;
54+ var ident = module . identifier ( ) ;
55+ return ! excludeModules . some ( function ( regExp ) {
56+ return regExp . test ( ident ) ;
57+ } ) ;
58+ }
4359
4460 function sortByField ( field ) {
4561 if ( ! field ) return function ( ) { return 0 ; }
@@ -184,12 +200,8 @@ Stats.prototype.toJson = function toJson(options, forToString) {
184200 } )
185201 } ;
186202 if ( showChunkModules ) {
187- obj . modules = chunk . modules . map ( fnModule ) ;
188- if ( ! showCachedModules ) {
189- obj . modules = obj . modules . filter ( function ( m ) {
190- return m . built ;
191- } ) ;
192- }
203+ obj . modules = chunk . modules . filter ( moduleFilter ) . map ( fnModule ) ;
204+ obj . filteredModules = chunk . modules . length - obj . modules . length ;
193205 obj . modules . sort ( sortByField ( sortModules ) ) ;
194206 }
195207 if ( showChunkOrigins ) {
@@ -211,12 +223,8 @@ Stats.prototype.toJson = function toJson(options, forToString) {
211223 obj . chunks . sort ( sortByField ( sortChunks ) ) ;
212224 }
213225 if ( showModules ) {
214- obj . modules = compilation . modules . map ( fnModule ) ;
215- if ( ! showCachedModules ) {
216- obj . modules = obj . modules . filter ( function ( m ) {
217- return m . built ;
218- } ) ;
219- }
226+ obj . modules = compilation . modules . filter ( moduleFilter ) . map ( fnModule ) ;
227+ obj . filteredModules = compilation . modules . length - obj . modules . length ;
220228 obj . modules . sort ( sortByField ( sortModules ) ) ;
221229 }
222230 if ( showChildren ) {
@@ -523,6 +531,10 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
523531 }
524532 processProfile ( module ) ;
525533 } ) ;
534+ if ( chunk . filteredModules > 0 ) {
535+ normal ( " + " + chunk . filteredModules + " hidden modules" ) ;
536+ newline ( ) ;
537+ }
526538 }
527539 } ) ;
528540 }
@@ -557,6 +569,10 @@ Stats.jsonToString = function jsonToString(obj, useColors) {
557569 }
558570 processProfile ( module ) ;
559571 } ) ;
572+ if ( obj . filteredModules > 0 ) {
573+ normal ( " + " + obj . filteredModules + " hidden modules" ) ;
574+ newline ( ) ;
575+ }
560576 }
561577 if ( obj . warnings ) {
562578 obj . warnings . forEach ( function ( warning ) {
0 commit comments