Skip to content

Commit

Permalink
Merge branch 'release/2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
benurb committed Aug 3, 2017
2 parents 8e2b546 + 1e4a459 commit c9b36fc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example/src/basename.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Only add basename");
console.log("Only add basename");
14 changes: 5 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class StatsReplacePlugin {
* @typedef {Object} Config
* @property {String} asset - Final name of the asset whose content should be changed. It has to be a part
* of the same webpack module as the assets defined in Replacers.
* @property {Boolean} basename - If set to true only the basename of the files matched by replacers.asset is appended
* @property {Boolean} basename - If true, only the basename of the files matched by replacers.asset is appended
* @property {Replacer[]} replacers - Replacers that are run against the given asset file
*/

Expand All @@ -29,11 +29,6 @@ class StatsReplacePlugin {
*/
constructor(configArray) {
this.configArray = configArray;

// We store a list of assets this plugin has already "seen" in a compilation. This is used for
// webpack-dev-server as some loaders (e.g. the css-loader) do not remove assets from previous builds from the
// compilation, but just add the newest
this.knownAssets = [];
}

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

process(compilation) {
const assetNames = Object.keys(compilation.assets);
const newAssetNames = assetNames.filter((assetName) => this.knownAssets.indexOf(assetName) === -1);

// 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);

for (const config of this.configArray) {
for (const assetName of assetNames) {
Expand Down Expand Up @@ -89,8 +87,6 @@ class StatsReplacePlugin {
console.log(`[${assetName}] ${match} => ${relatedAsset}`);
return relatedAsset;
});

this.knownAssets.push(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.0",
"version": "2.1.1",
"description": "Fills placeholders in text files with the final name of compiled assets",
"main": "lib/index.js",
"directories": {
Expand Down

0 comments on commit c9b36fc

Please sign in to comment.