@@ -7,7 +7,6 @@ import { ManifestManager } from './ManifestManager';
77import { StatsManager } from './StatsManager' ;
88import { PLUGIN_IDENTIFIER } from './constants' ;
99import logger from './logger' ;
10- import { StatsInfo , ManifestInfo , ResourceInfo } from './types' ;
1110
1211export class StatsPlugin implements WebpackPluginInstance {
1312 readonly name = 'StatsPlugin' ;
@@ -62,26 +61,63 @@ export class StatsPlugin implements WebpackPluginInstance {
6261 ) ;
6362 // new rspack should hit
6463 if ( existedStats ) {
65- const updatedStats = this . _statsManager . updateStats (
64+ let updatedStats = this . _statsManager . updateStats (
6665 JSON . parse ( existedStats . source . source ( ) . toString ( ) ) ,
6766 compiler ,
68- compilation ,
6967 ) ;
70- this . _manifestManager . updateManifest ( {
68+ if (
69+ typeof this . _options . manifest === 'object' &&
70+ this . _options . manifest . additionalData
71+ ) {
72+ updatedStats =
73+ ( await this . _options . manifest . additionalData ( {
74+ stats : updatedStats ,
75+ compiler,
76+ compilation,
77+ bundler : this . _bundler ,
78+ } ) ) || updatedStats ;
79+ }
80+
81+ compilation . updateAsset (
82+ this . _statsManager . fileName ,
83+ new compiler . webpack . sources . RawSource (
84+ JSON . stringify ( updatedStats , null , 2 ) ,
85+ ) ,
86+ ) ;
87+ const updatedManifest = this . _manifestManager . updateManifest ( {
7188 compilation,
7289 stats : updatedStats ,
7390 publicPath : this . _statsManager . getPublicPath ( compiler ) ,
7491 compiler,
7592 bundler : this . _bundler ,
7693 } ) ;
94+ const source = new compiler . webpack . sources . RawSource (
95+ JSON . stringify ( updatedManifest , null , 2 ) ,
96+ ) ;
97+ compilation . updateAsset ( this . _manifestManager . fileName , source ) ;
98+
7799 return ;
78100 }
79101
80102 // webpack + legacy rspack
81- const stats = await this . _statsManager . generateStats (
103+ let stats = await this . _statsManager . generateStats (
82104 compiler ,
83105 compilation ,
84106 ) ;
107+
108+ if (
109+ typeof this . _options . manifest === 'object' &&
110+ this . _options . manifest . additionalData
111+ ) {
112+ stats =
113+ ( await this . _options . manifest . additionalData ( {
114+ stats,
115+ compiler,
116+ compilation,
117+ bundler : this . _bundler ,
118+ } ) ) || stats ;
119+ }
120+
85121 const manifest = await this . _manifestManager . generateManifest ( {
86122 compilation,
87123 stats : stats ,
@@ -90,18 +126,6 @@ export class StatsPlugin implements WebpackPluginInstance {
90126 bundler : this . _bundler ,
91127 } ) ;
92128
93- if (
94- typeof this . _options . manifest === 'object' &&
95- this . _options . manifest . additionalData
96- ) {
97- await this . _options . manifest . additionalData ( {
98- stats,
99- compiler,
100- compilation,
101- manifest,
102- bundler : this . _bundler ,
103- } ) ;
104- }
105129 compilation . emitAsset (
106130 this . _statsManager . fileName ,
107131 new compiler . webpack . sources . RawSource (
0 commit comments