Skip to content

Commit

Permalink
Merge pull request #421 from petercr/fix-webpack-compile-every-time
Browse files Browse the repository at this point in the history
Fixes [#241] Prevent Webpack compilers from running on every page.
  • Loading branch information
colbyfayock authored Oct 27, 2022
2 parents 0e6f793 + 1b6cea4 commit 8b25d05
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/plugin-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WebpackPlugin {
await createFile(file, plugin.name, plugin.outputDirectory, plugin.outputLocation, verbose);
}

//If there is an aditional action to perform
//If there is an additional action to perform
if (plugin.postcreate) {
plugin.postcreate(plugin);
}
Expand All @@ -53,15 +53,21 @@ class WebpackPlugin {

const { plugin } = this.options;

// Value to ensure that the plugins only run once and not continuously on every page request
let hasRun = false;

compiler.hooks.run.tap(plugin.name, async (compiler) => {
if (!compiler.options.entry.main) return;
if (!compiler.options.entry.main || hasRun) return;

await this.index(compiler, this.options);
hasRun = true;
});

compiler.hooks.watchRun.tap(plugin.name, async (compiler) => {
const entries = await compiler.options.entry();
if (!entries || !entries.main) return;
if (!entries || !entries.main || hasRun) return;
await this.index(compiler, this.options);
hasRun = true;
});
}
}
Expand Down

1 comment on commit 8b25d05

@vercel
Copy link

@vercel vercel bot commented on 8b25d05 Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.