You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/pluginsapi/compiler.md
+32-48Lines changed: 32 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ compiler.options = {...};
25
25
classLogPlugin {
26
26
apply (compiler) {
27
27
compiler.plugin('should-emit', compilation=> {
28
-
console.log('should i emit');
28
+
console.log('should i emit?');
29
29
returntrue;
30
30
})
31
31
}
@@ -47,7 +47,7 @@ compiler.run(callback);
47
47
```
48
48
49
49
The `Compiler` is what we call a `Tapable` instance. By this, we mean that it mixes in `Tapable` class to imbibe functionality to register and call plugins on itself.
50
-
All user facing plugins are first registered on the `Compiler`.
50
+
Most user facing plugins are first registered on the `Compiler`.
51
51
The working of a Compiler can be condensed into the following highlights
52
52
- Usually there is one master instance of Compiler. Child compilers can be created for delegating specific tasks.
53
53
- A lot of the complexity in creating a compiler goes into populating all the relevant options for it.
@@ -59,7 +59,7 @@ The working of a Compiler can be condensed into the following highlights
59
59
## Watching
60
60
61
61
However, the `Compiler` supports two flavors of execution. One on watch mode and one on a normal single run.
62
-
While it essentially performs the same functionality while watching, there are some subtle changes to the lifecycle events. This allows `webpack` to have Watch specific plugins.
62
+
While it essentially performs the same functionality while watching, there are some additions to the lifecycle events. This allows `webpack` to have Watch specific plugins.
63
63
64
64
## MultiCompiler
65
65
@@ -69,48 +69,32 @@ While it essentially performs the same functionality while watching, there are s
69
69
70
70
This a reference guide to all the event hooks exposed by the `Compiler`.
A plugin can be classified into types based on the event it is registered to. Every event hook decides how it is going to apply the plugins in its registry.
49
+
50
+
-__synchronous__ The Tapable instance applies plugins using
Here each of the plugins are called one after the other with the args from the return value of the previous plugin. The plugin must take into consider the order of its execution.
64
+
It must accept arguments from the previous plugin that was executed. The value for the first plugin is `init`. This pattern is used in the Tapable instances which are related to the `webpack` templates like `ModuleTemplate`, `ChunkTemplate` etc.
65
+
66
+
-__asynchronous__ When all the plugins are applied asynchronously using
The plugin handler functions are called with all args and a callback function with the signature `(err?: Error) -> void`. The hander functions are called in order of registration.`callback` is called after all the handlers are called.
71
+
This is also a commonly used pattern for events like `"emit"`, `"run"`.
72
+
73
+
-__async waterfall__ The plugins will be applied asynchronously in the waterfall manner.
The plugin handler functions are called with the current value and a callback function with the signature `(err: Error, nextValue: any) -> void.` When called `nextValue` is the current value for the next handler. The current value for the first handler is `init`. After all handlers are applied, callback is called with the last value. If any handler passes a value for `err`, the callback is called with this error and no more handlers are called.
78
+
This plugin pattern is expected for events like `"before-resolve"` and `"after-resolve"`.
79
+
80
+
-__async series__ It is the same as asynchronous but if any of the plugins registered fails, then no more plugins are called.
0 commit comments