Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
benurb committed Aug 3, 2017
2 parents c9b36fc + 68ff80f commit 3db618b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class StatsReplacePlugin {
*/
constructor(configArray) {
this.configArray = configArray;

this.lruAssets = {};
}

apply(compiler) {
Expand All @@ -43,7 +45,7 @@ class StatsReplacePlugin {

// Filter assets emitted in this compilation to make sure they have precedence over assets from previous
// compilations (important e.g. for webpack-dev-server)
const newAssetNames = assetNames.filter((assetName) => compilation.assets[assetName].emitted !== true);
const newAssetNames = assetNames.filter((assetName) => compilation.assets[assetName].emitted == null);

for (const config of this.configArray) {
for (const assetName of assetNames) {
Expand All @@ -68,6 +70,11 @@ class StatsReplacePlugin {
for (const replacer of config.replacers) {
let relatedAsset = newAssetNames.find((name) => replacer.asset.test(name));

// Select the least recently used asset
if (!relatedAsset) {
relatedAsset = this.lruAssets[replacer.asset.toString()];
}

// Only check all assets if there is no matching new one
if (!relatedAsset) {
relatedAsset = assetNames.find((name) => replacer.asset.test(name));
Expand All @@ -87,6 +94,8 @@ class StatsReplacePlugin {
console.log(`[${assetName}] ${match} => ${relatedAsset}`);
return relatedAsset;
});

this.lruAssets[replacer.asset.toString()] = relatedAsset;
}

compilation.assets[assetName] = new RawSource(Buffer.from(content, "utf8"));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stats-replace-webpack-plugin",
"version": "2.1.1",
"version": "2.2.0",
"description": "Fills placeholders in text files with the final name of compiled assets",
"main": "lib/index.js",
"directories": {
Expand Down

0 comments on commit 3db618b

Please sign in to comment.