From e07264092e5b9b8a732162b9bf935697afd423e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 15 Jul 2024 13:22:01 -0400 Subject: [PATCH 1/2] Add examples of utils.createHash --- src/content/api/loaders.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/content/api/loaders.mdx b/src/content/api/loaders.mdx index 65edd125dd27..7a0588baaa4e 100644 --- a/src/content/api/loaders.mdx +++ b/src/content/api/loaders.mdx @@ -569,10 +569,11 @@ Example values: `'web'`, `'node'` -Access to `contextify` and `absolutify` utilities. +Access to the following utilities. -- `contextify`: Return a new request string avoiding absolute paths when possible. - `absolutify`: Return a new request string using absolute paths when possible. +- `contextify`: Return a new request string avoiding absolute paths when possible. +- `createHash`: Return a new Hash object from provided hash function. **my-sync-loader.js** @@ -583,6 +584,11 @@ module.exports = function (content) { this.utils.absolutify(this.context, './index.js') ); this.utils.absolutify(this.context, this.resourcePath); + const mainHash = this.utils.createHash( + this._compilation.outputOptions.hashFunction + ); + mainHash.update(content); + mainHash.digest("hex"); // … return content; }; From abc25c8b2a71d874b7523ada7bb755b0bed61816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 15 Jul 2024 13:27:11 -0400 Subject: [PATCH 2/2] Update loaders.mdx --- src/content/api/loaders.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/api/loaders.mdx b/src/content/api/loaders.mdx index 7a0588baaa4e..c26696d357cf 100644 --- a/src/content/api/loaders.mdx +++ b/src/content/api/loaders.mdx @@ -588,7 +588,7 @@ module.exports = function (content) { this._compilation.outputOptions.hashFunction ); mainHash.update(content); - mainHash.digest("hex"); + mainHash.digest('hex'); // … return content; };