Skip to content

Instantly share code, notes, and snippets.

@SarKurd
Created February 11, 2020 21:32
Show Gist options
  • Select an option

  • Save SarKurd/222f1258871277c0cc295a6add4369c5 to your computer and use it in GitHub Desktop.

Select an option

Save SarKurd/222f1258871277c0cc295a6add4369c5 to your computer and use it in GitHub Desktop.
Mini css extract plugin clean up
//https://github.com/webpack/webpack/issues/7300#issuecomment-413959996
class MiniCssExtractPluginCleanUp {
constructor(deleteWhere = /styles(\.[^.]+)?\.js(\.map)?$/) {
this.shouldDelete = new RegExp(deleteWhere);
}
apply(compiler) {
compiler.hooks.emit.tapAsync('MiniCssExtractPluginCleanup', (compilation, callback) => {
Object.keys(compilation.assets).forEach(asset => {
if (this.shouldDelete.test(asset)) {
delete compilation.assets[asset];
}
});
callback();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment