@@ -56,6 +56,7 @@ class BundleTrackerPlugin {
5656 } ;
5757 this . name = 'BundleTrackerPlugin' ;
5858
59+ this . output = { } ;
5960 this . outputChunkDir = '' ;
6061 this . outputTrackerFile = '' ;
6162 this . outputTrackerDir = '' ;
@@ -145,29 +146,8 @@ class BundleTrackerPlugin {
145146 _handleCompile ( compiler ) {
146147 this . _writeOutput ( compiler , { status : 'compile' } ) ;
147148 }
148- /**
149- * Handle compile hook
150- * @param {Compiler } compiler
151- * @param {Stats } stats
152- */
153- _handleDone ( compiler , stats ) {
154- if ( stats . hasErrors ( ) ) {
155- const findError = compilation => {
156- if ( compilation . errors . length > 0 ) {
157- return compilation . errors [ 0 ] ;
158- }
159- return compilation . children . find ( child => findError ( child ) ) ;
160- } ;
161- const error = findError ( stats . compilation ) ;
162- this . _writeOutput ( compiler , {
163- status : 'error' ,
164- error : error ?. name ?? 'unknown-error' ,
165- message : stripAnsi ( error [ 'message' ] ) ,
166- } ) ;
167-
168- return ;
169- }
170149
150+ _handleAssetEmitted ( _compiler , _ , stats ) {
171151 /** @type {Contents } */
172152 const output = { status : 'done' , assets : { } , chunks : { } } ;
173153 Object . entries ( stats . compilation . assets ) . map ( ( [ assetName , _ ] ) => {
@@ -200,19 +180,46 @@ class BundleTrackerPlugin {
200180
201181 output . assets [ assetName ] = fileInfo ;
202182 } ) ;
183+ this . output = output ;
184+ }
185+
186+ /**
187+ * Handle compile hook
188+ * @param {Compiler } compiler
189+ * @param {Stats } stats
190+ */
191+ _handleDone ( compiler , stats ) {
192+ if ( stats . hasErrors ( ) ) {
193+ const findError = compilation => {
194+ if ( compilation . errors . length > 0 ) {
195+ return compilation . errors [ 0 ] ;
196+ }
197+ return compilation . children . find ( child => findError ( child ) ) ;
198+ } ;
199+ const error = findError ( stats . compilation ) ;
200+ this . _writeOutput ( compiler , {
201+ status : 'error' ,
202+ error : error ?. name ?? 'unknown-error' ,
203+ message : stripAnsi ( error [ 'message' ] ) ,
204+ } ) ;
205+
206+ return ;
207+ }
208+
203209 stats . compilation . chunkGroups . forEach ( chunkGroup => {
204210 if ( ! chunkGroup . isInitial ( ) ) return ;
205211
206- output . chunks [ chunkGroup . name ] = chunkGroup . getFiles ( ) ;
212+ this . output . chunks [ chunkGroup . name ] = chunkGroup . getFiles ( ) ;
207213 } ) ;
208214
209215 if ( this . options . logTime === true ) {
210- output . startTime = stats . startTime ;
211- output . endTime = stats . endTime ;
216+ this . output . startTime = stats . startTime ;
217+ this . output . endTime = stats . endTime ;
212218 }
213219
214- this . _writeOutput ( compiler , output ) ;
220+ this . _writeOutput ( compiler , this . output ) ;
215221 }
222+
216223 /**
217224 * Method called by webpack to apply plugin hook
218225 * @param {Compiler } compiler
@@ -221,6 +228,7 @@ class BundleTrackerPlugin {
221228 this . _setParamsFromCompiler ( compiler ) ;
222229
223230 compiler . hooks . compile . tap ( this . name , this . _handleCompile . bind ( this , compiler ) ) ;
231+ compiler . hooks . assetEmitted . tap ( this . name , this . _handleAssetEmitted . bind ( this , compiler ) ) ;
224232 compiler . hooks . done . tap ( this . name , this . _handleDone . bind ( this , compiler ) ) ;
225233 }
226234}
0 commit comments