Skip to content

Commit

Permalink
Improved handling of persistent cache assets
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeveric committed Mar 27, 2021
1 parent 62b0a73 commit 0b323fc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/WebpackAssetsManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,29 @@ class WebpackAssetsManifest
}
}

/**
* When using webpack 5 persistent cache, loaderContext.emitFile sometimes doesn't
* get called and so the asset names are not recorded. To work around this, lets
* loops over the stats.assets and record the asset names.
*
* @param {Object[]} assets
*/
processStatsAssets(assets)
{
const { contextRelativeKeys } = this.options;

assets.forEach( asset => {
if ( asset.name && asset.info.sourceFilename ) {
this.assetNames.set(
contextRelativeKeys ?
asset.info.sourceFilename :
path.join( path.dirname(asset.name), path.basename(asset.info.sourceFilename) ),
asset.name,
);
}
});
}

/**
* Gather asset details
*
Expand All @@ -512,10 +535,14 @@ class WebpackAssetsManifest
const stats = compilation.getStats().toJson({
all: false,
assets: true,
cachedAssets: true,
cachedModules: true,
chunkGroups: this.options.entrypoints,
chunkGroupChildren: this.options.entrypoints,
});

this.processStatsAssets( stats.assets );

this.processAssetsByChunkName( stats.assetsByChunkName );

const findAssetKeys = findMapKeysByValue( this.assetNames );
Expand Down

0 comments on commit 0b323fc

Please sign in to comment.