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.mdx
+16-2
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,16 @@ contributors:
14
14
- snitin315
15
15
- chenxsan
16
16
- jamesgeorge007
17
+
- alexeyr
17
18
---
18
19
19
20
A loader is a JavaScript module that exports a function. The [loader runner](https://github.com/webpack/loader-runner) calls this function and passes the result of the previous loader or the resource file into it. The `this` context of the function is filled-in by webpack and the [loader runner](https://github.com/webpack/loader-runner) with some useful methods that allow the loader (among other things) to change its invocation style to async, or get query parameters.
20
21
21
22
The first loader is passed one argument: the content of the resource file. The compiler expects a result from the last loader. The result should be a `String` or a `Buffer` (which is converted to a string), representing the JavaScript source code of the module. An optional SourceMap result (as a JSON object) may also be passed.
22
23
23
-
A single result can be returned in [sync mode](#synchronous-loaders). For multiple results the `this.callback()` must be called. In [async mode](#asynchronous-loaders)`this.async()` must be called to indicate that the [loader runner](https://github.com/webpack/loader-runner) should wait for an asynchronous result. It returns `this.callback()`. Then the loader must return `undefined` and call that callback.
24
+
A single result can be returned in [sync mode](#synchronous-loaders). For multiple results the `this.callback()` must be called and the loader must return `undefined`.
25
+
26
+
In [async mode](#asynchronous-loaders) you can return a single result from an `async function`. Alternatively, you may call `this.async()` to indicate that the [loader runner](https://github.com/webpack/loader-runner) should wait for an asynchronous result. It returns `this.callback()`. In this case the loader must return `undefined` and call that callback. This is the only option for multiple results.
0 commit comments