API - Document When a Plugin Should Call doResolve() · Issue #1458 · webpack/webpack.js.org (original) (raw)

Do you want to request a feature or report a bug?
Documentation request

What is the current behavior?

No documentation about how plugins are processed

What is the expected behavior?

Every webpack plugin follows the following structure:

resolver.plugin(this.source, function(request, callback) {
    if (something) {
         resolver.doResolve(target, obj, "aliased with mapping '" + name + "': '" + ...)
    } else {
         callback(...);
    }

Can anyone please explain when I should call doResolve(...) and when callback(...). I've found this phrase in the webpack docs:

To pass the request to other resolving plugins, use the this.doResolve(types: String|String[], request: Request, callback) method

However, I don't know what to make of it.

It seems that doResolve starts the process from the start - resolve types are repeated. Inside doResolve the callback.stack has the following entries:

[
    "resolve: (/d/...",    <------------- resolve here
    "new-resolve: (/d/...",
    "parsed-resolve: (/d/...",
    "described-resolve: (/d/...",
    "resolve: (/d/...",    <--------------- and it's repeated here
    "new-resolve: (/d/...",
    "parsed-resolve: (/d/...",
    ...
]

Here is the screenshot. Why does that happen?

Here is how the stack looks like in doResolve.

And also all plugins that hook into resolve events use the function getInnerRequest(resolver, request);. What is inner request?

If this is a feature request, what is motivation or use case for changing the behavior?

It's hard to write a plugin without understanding the processing flow. I'm not asking for a full-blown detailed documentation, maybe just a small passage explaining the matter in general terms so that I get correct mindset when exploring the code through the debugger.


This issue was moved from webpack/webpack#5380 by @sokra. Orginal issue was by @MaximusK.