@@ -29,6 +29,8 @@ class StatsReplacePlugin {
2929 */
3030 constructor ( configArray ) {
3131 this . configArray = configArray ;
32+
33+ this . lruAssets = { } ;
3234 }
3335
3436 apply ( compiler ) {
@@ -43,7 +45,7 @@ class StatsReplacePlugin {
4345
4446 // Filter assets emitted in this compilation to make sure they have precedence over assets from previous
4547 // compilations (important e.g. for webpack-dev-server)
46- const newAssetNames = assetNames . filter ( ( assetName ) => compilation . assets [ assetName ] . emitted ! == true ) ;
48+ const newAssetNames = assetNames . filter ( ( assetName ) => compilation . assets [ assetName ] . emitted == null ) ;
4749
4850 for ( const config of this . configArray ) {
4951 for ( const assetName of assetNames ) {
@@ -68,6 +70,11 @@ class StatsReplacePlugin {
6870 for ( const replacer of config . replacers ) {
6971 let relatedAsset = newAssetNames . find ( ( name ) => replacer . asset . test ( name ) ) ;
7072
73+ // Select the least recently used asset
74+ if ( ! relatedAsset ) {
75+ relatedAsset = this . lruAssets [ replacer . asset . toString ( ) ] ;
76+ }
77+
7178 // Only check all assets if there is no matching new one
7279 if ( ! relatedAsset ) {
7380 relatedAsset = assetNames . find ( ( name ) => replacer . asset . test ( name ) ) ;
@@ -87,6 +94,8 @@ class StatsReplacePlugin {
8794 console . log ( `[${ assetName } ] ${ match } => ${ relatedAsset } ` ) ;
8895 return relatedAsset ;
8996 } ) ;
97+
98+ this . lruAssets [ replacer . asset . toString ( ) ] = relatedAsset ;
9099 }
91100
92101 compilation . assets [ assetName ] = new RawSource ( Buffer . from ( content , "utf8" ) ) ;
0 commit comments