Skip to content

Commit 57d5a55

Browse files
authored
docs(api): document this.utils in loader context (webpack#4780)
* docs(api): document this.utils * add badge * add descriptions
1 parent 0e6e299 commit 57d5a55

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/content/api/loaders.md renamed to src/content/api/loaders.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,29 @@ Read in which [`mode`](/configuration/mode/) webpack is running.
466466
467467
Possible values: `'production'`, `'development'`, `'none'`
468468
469+
### this.utils
470+
471+
<Badge text="5.27.0+" />
472+
473+
Access to `contextify` and `absolutify` utilities.
474+
475+
- `contextify`: Return a new request string avoiding absolute paths when possible.
476+
- `absolutify`: Return a new request string using absolute paths when possible.
477+
478+
**my-sync-loader.js**
479+
480+
```js
481+
module.exports = function (content) {
482+
this.utils.contextify(
483+
this.context,
484+
this.utils.absolutify(this.context, './index.js')
485+
);
486+
this.utils.absolutify(this.context, this.resourcePath);
487+
//
488+
return content;
489+
};
490+
```
491+
469492
## Webpack specific properties
470493
471494
The loader interface provides all module relate information. However in rare cases you might need access to the compiler api itself.

0 commit comments

Comments
 (0)