@@ -196,16 +196,17 @@ export class NgBuildAnalyticsPlugin {
196
196
}
197
197
}
198
198
199
- // We can safely disable no any here since we know the format of the JSON output from webpack.
200
- // tslint:disable-next-line:no-any
201
- protected _collectBundleStats ( json : any ) {
202
- json . chunks
199
+ protected _collectBundleStats ( compilation : compilation . Compilation ) {
200
+ // `compilation.chunks` is a Set in Webpack 5
201
+ const chunks = Array . from ( compilation . chunks ) ;
202
+
203
+ chunks
203
204
. filter ( ( chunk : { rendered ?: boolean } ) => chunk . rendered )
204
- . forEach ( ( chunk : { files : string [ ] , initial ?: boolean , entry ? : boolean } ) => {
205
- const asset = json . assets . find ( ( x : { name : string } ) => x . name == chunk . files [ 0 ] ) ;
206
- const size = asset ? asset . size : 0 ;
205
+ . forEach ( ( chunk : { files : string [ ] ; canBeInitial ( ) : boolean } ) => {
206
+ const asset = compilation . assets [ chunk . files [ 0 ] ] ;
207
+ const size = asset ? asset . size ( ) : 0 ;
207
208
208
- if ( chunk . entry || chunk . initial ) {
209
+ if ( chunk . canBeInitial ( ) ) {
209
210
this . _stats . initialChunkSize += size ;
210
211
} else {
211
212
this . _stats . lazyChunkCount ++ ;
@@ -215,24 +216,26 @@ export class NgBuildAnalyticsPlugin {
215
216
this . _stats . totalChunkSize += size ;
216
217
} ) ;
217
218
218
- json . assets
219
+ Object . entries < { size ( ) : number } > ( compilation . assets )
219
220
// Filter out chunks. We only count assets that are not JS.
220
- . filter ( ( a : { name : string } ) => {
221
- return json . chunks . every ( ( chunk : { files : string [ ] } ) => chunk . files [ 0 ] != a . name ) ;
221
+ . filter ( ( [ name ] ) => {
222
+ return chunks . every ( ( chunk : { files : string [ ] } ) => chunk . files [ 0 ] != name ) ;
222
223
} )
223
- . forEach ( ( a : { size ?: number } ) => {
224
- this . _stats . assetSize += ( a . size || 0 ) ;
224
+ . forEach ( ( [ , asset ] ) => {
225
+ this . _stats . assetSize += asset . size ( ) ;
225
226
this . _stats . assetCount ++ ;
226
227
} ) ;
227
228
228
- for ( const asset of json . assets ) {
229
- if ( asset . name == 'polyfill' ) {
230
- this . _stats . polyfillSize += asset . size || 0 ;
229
+ for ( const [ name , asset ] of Object . entries < { size ( ) : number } > ( compilation . assets ) ) {
230
+ if ( name == 'polyfill' ) {
231
+ this . _stats . polyfillSize += asset . size ( ) ;
231
232
}
232
233
}
233
- for ( const chunk of json . chunks ) {
234
+ for ( const chunk of compilation . chunks ) {
234
235
if ( chunk . files [ 0 ] && chunk . files [ 0 ] . endsWith ( '.css' ) ) {
235
- this . _stats . cssSize += chunk . size || 0 ;
236
+ const asset = compilation . assets [ chunk . files [ 0 ] ] ;
237
+ const size = asset ? asset . size ( ) : 0 ;
238
+ this . _stats . cssSize += size ;
236
239
}
237
240
}
238
241
}
@@ -276,7 +279,7 @@ export class NgBuildAnalyticsPlugin {
276
279
277
280
protected _done ( stats : Stats ) {
278
281
this . _collectErrors ( stats ) ;
279
- this . _collectBundleStats ( stats . toJson ( ) ) ;
282
+ this . _collectBundleStats ( stats . compilation ) ;
280
283
if ( this . _built ) {
281
284
this . _reportRebuildMetrics ( stats ) ;
282
285
} else {
0 commit comments