Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chunks to include compressed files #186

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,19 @@ class CompressionPlugin {
}
}

static emitAsset(compilation, name, source, assetInfo) {
static emitAsset(compilation, name, source, assetInfo, oldName) {
// New API
if (compilation.emitAsset) {
compilation.emitAsset(name, source, assetInfo);
}


// Update chunks to include new asset name as well
compilation.chunks.forEach((chunk) => {
if(chunk.files.includes(oldName)) {
chunk.files.push(name);
}
});

// eslint-disable-next-line no-param-reassign
compilation.assets[name] = source;
}
Expand All @@ -122,7 +129,7 @@ class CompressionPlugin {
if (compilation.updateAsset) {
compilation.updateAsset(name, newSource, assetInfo);
}

// eslint-disable-next-line no-param-reassign
compilation.assets[name] = newSource;
}
Expand Down Expand Up @@ -224,7 +231,7 @@ class CompressionPlugin {

CompressionPlugin.emitAsset(compilation, newAssetName, output, {
compressed: true,
});
}, assetName);

if (this.options.deleteOriginalAssets) {
// eslint-disable-next-line no-param-reassign
Expand Down