@@ -11,27 +11,28 @@ class ManifestVersionSyncPlugin {
1111 }
1212
1313 apply ( compiler ) {
14- compiler . hooks . emit . tapAsync ( 'ManifestVersionSyncPlugin' , ( compilation , callback ) => {
15- // Skip watch mode
16- if ( compilation . options . watch ) {
17- return callback ( ) ;
18- }
14+ compiler . hooks . compilation . tap ( 'ManifestVersionSyncPlugin' , ( compilation , compilationParams ) => {
15+ compilation . hooks . afterProcessAssets . tap ( 'ManifestVersionSyncPlugin' , ( ) => {
16+ const { packagePath, manifestPath } = this . options ;
1917
20- const { packagePath, manifestPath } = this . options ;
21- const { version } = JSON . parse ( fs . readFileSync ( packagePath ) . toString ( ) ) ;
22- const manifest = JSON . parse ( compilation . assets [ manifestPath ] . source ( ) . toString ( ) ) ;
23- const content = JSON . stringify ( { ...manifest , version } , undefined , 2 ) ;
24-
25- compilation . assets [ manifestPath ] = {
26- source : function ( ) {
27- return content ;
28- } ,
29- size : function ( ) {
30- return Buffer . byteLength ( content ) ;
31- } ,
32- } ;
33-
34- callback ( ) ;
18+ // Skip watch mode
19+ if ( compilation . options . watch || compilation . assets [ manifestPath ] == undefined ) {
20+ return ;
21+ }
22+
23+ const { version } = JSON . parse ( fs . readFileSync ( packagePath ) . toString ( ) ) ;
24+ const manifest = JSON . parse ( compilation . assets [ manifestPath ] . source ( ) . toString ( ) ) ;
25+ const content = JSON . stringify ( { ...manifest , version } , undefined , 2 ) ;
26+
27+ compilation . assets [ manifestPath ] = {
28+ source : function ( ) {
29+ return content ;
30+ } ,
31+ size : function ( ) {
32+ return Buffer . byteLength ( content ) ;
33+ } ,
34+ } ;
35+ } ) ;
3536 } ) ;
3637 }
3738}
0 commit comments