Skip to content

Commit 5a66029

Browse files
docs(configuration): add example for loader option (#3927)
* docs(configuration): add example for loader option * Apply suggestion Co-authored-by: Eugene Hlushko <[email protected]> * add filename * Apply suggestions from code review Co-authored-by: Eugene Hlushko <[email protected]> Co-authored-by: Eugene Hlushko <[email protected]>
1 parent 1b93cdf commit 5a66029

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/content/configuration/other-options.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,34 @@ W> `cache.idleTimeoutForInitialStore` is only available when [`cache.store`](#ca
306306

307307
`object`
308308

309-
Expose custom values into the loader context.
309+
Expose custom values into the [loader context](/api/loaders/#the-loader-context).
310310

311-
?> Add an example...
311+
For example, you can define a new variable in the loader context:
312312

313+
__webpack.config.js__
314+
315+
```javascript
316+
module.exports = {
317+
// ...
318+
loader: {
319+
answer: 42
320+
}
321+
};
322+
```
323+
324+
Then use `this.answer` to get its value in the loader:
325+
326+
__custom-loader.js__
327+
328+
```javascript
329+
module.exports = function (source) {
330+
// ...
331+
console.log(this.answer); // will log `42` here
332+
return source;
333+
};
334+
```
335+
336+
T> You can override properties in the loader context as webpack copies all properties that are defined in the `loader` to the loader context.
313337

314338
## `parallelism`
315339

0 commit comments

Comments
 (0)