Skip to content

Commit f2d88fa

Browse files
authored
docs(api): Add an example for utils.createHash (#7313)
* Add examples of utils.createHash * Update loaders.mdx
1 parent 2ec1209 commit f2d88fa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/content/api/loaders.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,11 @@ Example values: `'web'`, `'node'`
569569

570570
<Badge text="5.27.0+" />
571571

572-
Access to `contextify` and `absolutify` utilities.
572+
Access to the following utilities.
573573

574-
- `contextify`: Return a new request string avoiding absolute paths when possible.
575574
- `absolutify`: Return a new request string using absolute paths when possible.
575+
- `contextify`: Return a new request string avoiding absolute paths when possible.
576+
- `createHash`: Return a new Hash object from provided hash function.
576577

577578
**my-sync-loader.js**
578579

@@ -583,6 +584,11 @@ module.exports = function (content) {
583584
this.utils.absolutify(this.context, './index.js')
584585
);
585586
this.utils.absolutify(this.context, this.resourcePath);
587+
const mainHash = this.utils.createHash(
588+
this._compilation.outputOptions.hashFunction
589+
);
590+
mainHash.update(content);
591+
mainHash.digest('hex');
586592
//
587593
return content;
588594
};

0 commit comments

Comments
 (0)