question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support async evaluation for compiler hooks

See original GitHub issue

Feature request

Add a new async compiler hook at the beginning of compiler initialization, or turn most of sync hooks like entryOption to async.

What is the expected behavior? A plugin should be able to perform asynchronous tasks at any hooks specially at compiler initialization and configuration.

What is motivation or use case for adding/changing the behavior? There is some cases that plugin needs to evaluate for example new entries and this must be asynchronous, today this cannot be done as per all the hooks before, including entryOption, are synchronous.

How should this be implemented in your opinion? Refactor related sync process to async.

Are you willing to work on this yourself? Yes.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sokracommented, Aug 2, 2021

Compiler initialization need to stay sync. You can add async logic to determine entries. This is even supported without plugins:

// webpack.config.js
module.exports = {
  entry: async () => {
    await doSomething();
    return { main: "./main.js" };
  }
}
0reactions
alexander-akaitcommented, Aug 2, 2021

You can use https://github.com/webpack/webpack/blob/main/lib/index.js, i.e.

const DynamicEntryPlugin = require("./DynamicEntryPlugin");
new DynamicEntryPlugin(compiler.context, async () => {}).apply(compiler);

in your plugin and add entry dynamically

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compiler Hooks | webpack
The Compiler supports watching which monitors the file system and recompiles ... Depending on the hook type, tapAsync and tapPromise may also be...
Read more >
Change the webpack hook to use async tapPromises · Issue #9
I can create a PR to use a different async webpack hook that appears to ... async https://webpack.js.org/api/compiler-hooks/#afterplugins.
Read more >
Performing Async Actions using Hooks - Level Up Coding
This simple hook gives us current state action to be performed and a function to perform the action. The body argument is in...
Read more >
Testing asynchronous useEffect - Stack Overflow
I'm unit testing a hook but the principles should be the same if your async useEffect code is in a component. The problem....
Read more >
Compiler - webpack 3 documentation
The Compiler supports "watch mode" which monitors the file system and recompiles ... This a reference guide to all the event hooks exposed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found