Skip to content

Commit

Permalink
fix: Simplify mini-css-extract-plugin fix (#44)
Browse files Browse the repository at this point in the history
It looks like there's a specific API in webpack 5 to guarantee emitting only once.
  • Loading branch information
bebraw authored Oct 20, 2020
1 parent 054add6 commit 9d4cacb
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,12 @@ class MiniHtmlWebpackPlugin implements WebpackPluginInstance {

public apply(compiler: webpack.Compiler) {
const pluginName = 'MiniHtmlWebpackPlugin';
let registeredAlready = false;

if (isWebpack4()) {
// @ts-ignore: Ignore for webpack 4 due to different typing
compiler.hooks.emit.tapAsync(pluginName, this.webpack4plugin);
} else {
compiler.hooks.compilation.tap(pluginName, (compilation) => {
if (registeredAlready) {
return;
}

compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.processAssets.tapPromise(
{
name: pluginName,
Expand All @@ -240,8 +235,6 @@ class MiniHtmlWebpackPlugin implements WebpackPluginInstance {
},
() => this.webpack5plugin(compilation)
);

registeredAlready = true;
});
}
}
Expand Down

0 comments on commit 9d4cacb

Please sign in to comment.