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: src/content/api/plugins.md
+17-20Lines changed: 17 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,21 @@ T> For a high-level introduction to writing plugins, start with [writing a plugi
8
8
9
9
Many objects in webpack extend the `Tapable` class, which exposes a `plugin` method. And with the `plugin` method, plugins can inject custom build steps. You will see `compiler.plugin` and `compilation.plugin` used a lot. Essentially, each one of these plugin calls binds a callback to fire at specific steps throughout the build process.
10
10
11
+
There are two types of plugin interfaces...
12
+
13
+
__Timing Based__
14
+
15
+
- sync (default): The plugin runs synchronously and returns its output.
16
+
- async: The plugin runs asynchronously and uses the give `callback` to return its output.
17
+
- parallel: The handlers are invoked in parallel.
18
+
19
+
__Return Value__
20
+
21
+
- not bailing (default): No return value.
22
+
- bailing: The handlers are invoked in order until one handler returns something.
23
+
- parallel bailing: The handlers are invoked in parallel (async). The first returned value (by order) is significant.
24
+
- waterfall: Each handler gets the result value of the last handler as an argument.
25
+
11
26
A plugin is installed once as webpack starts up. webpack installs a plugin by calling its `apply` method, and passes a reference to the webpack `compiler` object. You may then call `compiler.plugin` to access asset compilations and their individual build steps. An example would look like this:
12
27
13
28
__my-plugin.js__
@@ -50,30 +65,12 @@ plugins: [
50
65
```
51
66
52
67
53
-
## Plugin Interfaces
54
-
55
-
There are two types of plugin interfaces.
56
-
57
-
__Timing Based:__
58
-
59
-
- sync (default): As seen above. Use return.
60
-
- async: Last parameter is a callback. Signature: function(err, result)
61
-
- parallel: The handlers are invoked parallel (async).
62
-
63
-
__Return Value:__
64
-
65
-
- not bailing (default): No return value.
66
-
- bailing: The handlers are invoked in order until one handler returns something.
67
-
- parallel bailing: The handlers are invoked in parallel (async). The first returned value (by order) is significant.
68
-
- waterfall: Each handler gets the result value of the last handler as an argument.
69
-
70
-
71
-
## Tapable & Tapable instances
68
+
## Tapable & Tapable Instances
72
69
73
70
The plugin architecture is mainly possible for webpack due to an internal library named `Tapable`.
74
71
**Tapable Instances** are classes in the webpack source code which have been extended or mixed in from class `Tapable`.
75
72
76
73
For plugin authors, it is important to know which are the `Tapable` instances in the webpack source code. These instances provide a variety of event hooks into which custom plugins can be attached.
77
74
Hence, throughout this section are a list of all of the webpack `Tapable` instances (and their event hooks), which plugin authors can utilize.
78
75
79
-
For more information on `Tapable` visit the [tapable repository](https://github.com/webpack/tapable) or visit the [complete overview](./tapable)
76
+
For more information on `Tapable` visit the [complete overview](/api/tapable) or the [tapable repository](https://github.com/webpack/tapable).
0 commit comments