Skip to content

Commit 3db618b

Browse files
committed
Merge branch 'release/2.2.0'
2 parents c9b36fc + 68ff80f commit 3db618b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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"));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stats-replace-webpack-plugin",
3-
"version": "2.1.1",
3+
"version": "2.2.0",
44
"description": "Fills placeholders in text files with the final name of compiled assets",
55
"main": "lib/index.js",
66
"directories": {

0 commit comments

Comments
 (0)