@@ -119,11 +119,11 @@ export function showStats(stats) {
119119 let info = stats . toJson ( 'errors-only' ) ;
120120
121121 if ( stats . hasErrors ( ) ) {
122- info . errors . map ( stripBabelLoaderPrefix ) . forEach ( msg => error ( msg ) ) ;
122+ info . errors . map ( stripLoaderPrefix ) . forEach ( msg => error ( msg ) ) ;
123123 }
124124
125125 if ( stats . hasWarnings ( ) ) {
126- info . warnings . map ( stripBabelLoaderPrefix ) . forEach ( msg => warn ( msg ) ) ;
126+ info . warnings . map ( stripLoaderPrefix ) . forEach ( msg => warn ( msg ) ) ;
127127 }
128128
129129 return stats ;
@@ -133,10 +133,15 @@ export function writeJsonStats(stats) {
133133 let outputPath = resolve ( process . cwd ( ) , 'stats.json' ) ;
134134 let jsonStats = stats . toJson ( { json :true , chunkModules :true , source :false } ) ;
135135
136- jsonStats = ( jsonStats . children && jsonStats . children [ 0 ] ) || jsonStats ;
136+ function strip ( stats ) {
137+ stats . modules . forEach ( stripLoaderFromModuleNames ) ;
138+ stats . chunks . forEach ( c => {
139+ ( c . mapModules != null ? c . mapModules ( Object ) : c . modules . slice ( ) ) . forEach ( stripLoaderFromModuleNames ) ;
140+ } ) ;
141+ if ( stats . children ) stats . children . forEach ( strip ) ;
142+ }
137143
138- jsonStats . modules . forEach ( stripBabelLoaderFromModuleNames ) ;
139- jsonStats . chunks . forEach ( c => c . forEachModule ( stripBabelLoaderFromModuleNames ) ) ;
144+ strip ( jsonStats ) ;
140145
141146 return writeFile ( outputPath , JSON . stringify ( jsonStats ) ) . then ( ( ) => {
142147 process . stdout . write ( '\nWebpack output stats generated.\n\n' ) ;
@@ -146,19 +151,33 @@ export function writeJsonStats(stats) {
146151 } ) ;
147152}
148153
149- const keysToNormalize = [ 'identifier' , 'name' , 'module' , 'moduleName' , 'moduleIdentifier' ] ;
150-
151- const stripBabelLoaderPrefix = log => log . replace ( / @ ? \s * ( \. \/ ~ \/ b a b e l - l o a d e r \/ l i b \? { [ \s \S ] * ?} ! ) / g, '' ) ;
154+ const keysToNormalize = [
155+ 'issuer' ,
156+ 'issuerName' ,
157+ 'identifier' ,
158+ 'name' ,
159+ 'module' ,
160+ 'moduleName' ,
161+ 'moduleIdentifier'
162+ ] ;
163+
164+ /** Removes all loaders from any resource identifiers found in a string */
165+ function stripLoaderPrefix ( str ) {
166+ if ( typeof str === 'string' ) {
167+ return str . replace ( / ( ^ | \b | @ ) ( \. \/ ~ | \. { 0 , 2 } \/ [ ^ \s ] + \/ n o d e _ m o d u l e s ) \/ \w + - l o a d e r ( \/ [ ^ ? ! ] + ) ? ( \? \? [ \w _ . - ] + | \? ( { [ \s \S ] * ?} ) ? ) ? ! / g, '' ) ;
168+ }
169+ return str ;
170+ }
152171
153- function stripBabelLoaderFromModuleNames ( m ) {
154- keysToNormalize . forEach ( key => {
155- if ( key in m ) {
156- m [ key ] = stripBabelLoaderPrefix ( m [ key ] ) ;
172+ function stripLoaderFromModuleNames ( m ) {
173+ for ( let key in m ) {
174+ if ( m . hasOwnProperty ( key ) && m [ key ] != null && ~ keysToNormalize . indexOf ( key ) ) {
175+ m [ key ] = stripLoaderPrefix ( m [ key ] ) ;
157176 }
158- } ) ;
177+ }
159178
160179 if ( m . reasons ) {
161- m . reasons . forEach ( stripBabelLoaderFromModuleNames ) ;
180+ m . reasons . forEach ( stripLoaderFromModuleNames ) ;
162181 }
163182
164183 return m ;
0 commit comments