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/loaders.md
+48-6
Original file line number
Diff line number
Diff line change
@@ -90,24 +90,66 @@ module.exports.raw = true;
90
90
91
91
### Pitching Loader
92
92
93
-
Loaders are **always** called from right to left. But, in some cases, loaders do not care about the results of the previous loader or the resource. They only care about **metadata**. The `pitch` method on the loaders is called from **left to right** before the loaders are called (from right to left).
93
+
Loaders are __always__ called from right to left. There are some instances where the loader only cares about the __metadata__ behind a request and can ignore the results of the previous loader. The `pitch` method on loaders is called from __left to right__ before the loaders are actually executed (from right to left). For the following [`use`](/configuration/module#rule-use) configuration:
94
94
95
-
If a loader delivers a result in the `pitch` method the process turns around and skips the remaining loaders, continuing with the calls to the more left loaders. `data` can be passed between pitch and normal call.
95
+
```js
96
+
use: [
97
+
'a-loader',
98
+
'b-loader',
99
+
'c-loader'
100
+
]
101
+
```
102
+
103
+
These steps would occur:
104
+
105
+
```diff
106
+
|- a-loader `pitch`
107
+
|- b-loader `pitch`
108
+
|- c-loader `pitch`
109
+
|- requested module is picked up as a dependency
110
+
|- c-loader normal execution
111
+
|- b-loader normal execution
112
+
|- a-loader normal execution
113
+
```
114
+
115
+
So why might a loader take advantage of the "pitching" phase?
116
+
117
+
First, the `data` passed to the `pitch` method is exposed in the execution phase as well under `this.data` and could be useful for capturing and sharing information from earlier in the cycle.
Second, if a loader delivers a result in the `pitch` method the process turns around and skips the remaining loaders. In our example above, if the `b-loader`s `pitch` method returned something:
0 commit comments