@@ -12,22 +12,22 @@ const options = loaderUtils.getOptions(this);
1212```
1313
14141 . If ` this.query ` is a string:
15- - Tries to parse the query string and returns a new object
16- - Throws if it's not a valid query string
15+ - Tries to parse the query string and returns a new object
16+ - Throws if it's not a valid query string
17172 . If ` this.query ` is object-like, it just returns ` this.query `
18183 . In any other case, it just returns ` null `
1919
20- ** Please note:** The returned ` options ` object is * read-only * . It may be re-used across multiple invocations.
21- If you pass it on to another library, make sure to make a * deep copy * of it:
20+ ** Please note:** The returned ` options ` object is _ read-only _ . It may be re-used across multiple invocations.
21+ If you pass it on to another library, make sure to make a _ deep copy _ of it:
2222
2323``` javascript
2424const options = Object .assign (
25- {},
26- defaultOptions,
27- loaderUtils .getOptions (this ) // it is safe to pass null to Object.assign()
25+ {},
26+ defaultOptions,
27+ loaderUtils .getOptions (this ) // it is safe to pass null to Object.assign()
2828);
2929// don't forget nested objects or arrays
30- options .obj = Object .assign ({}, options .obj );
30+ options .obj = Object .assign ({}, options .obj );
3131options .arr = options .arr .slice ();
3232someLibrary (options);
3333```
@@ -42,16 +42,16 @@ If the loader options have been passed as loader query string (`loader?some¶
4242
4343Parses a passed string (e.g. ` loaderContext.resourceQuery ` ) as a query string, and returns an object.
4444
45- ``` javascript
45+ ``` javascript
4646const params = loaderUtils .parseQuery (this .resourceQuery ); // resource: `file?param1=foo`
4747if (params .param1 === " foo" ) {
48- // do something
48+ // do something
4949}
5050```
5151
5252The string is parsed like this:
5353
54- ``` text
54+ ``` text
5555 -> Error
5656? -> {}
5757?flag -> { flag: true }
@@ -168,35 +168,39 @@ Interpolates a filename template using multiple placeholders and/or a regular ex
168168The template and regular expression are set as query params called ` name ` and ` regExp ` on the current loader's context.
169169
170170``` javascript
171- const interpolatedName = loaderUtils .interpolateName (loaderContext, name, options);
171+ const interpolatedName = loaderUtils .interpolateName (
172+ loaderContext,
173+ name,
174+ options
175+ );
172176```
173177
174178The following tokens are replaced in the ` name ` parameter:
175179
176- * ` [ext] ` the extension of the resource
177- * ` [name] ` the basename of the resource
178- * ` [path] ` the path of the resource relative to the ` context ` query parameter or option.
179- * ` [folder] ` the folder the resource is in
180- * ` [query] ` the queryof the resource, i.e. ` ?foo=bar `
181- * ` [emoji] ` a random emoji representation of ` options.content `
182- * ` [emoji:<length>] ` same as above, but with a customizable number of emojis
183- * ` [contenthash] ` the hash of ` options.content ` (Buffer) (by default it's the hex digest of the md4 hash)
184- * ` [<hashType>:contenthash:<digestType>:<length>] ` optionally one can configure
185- * other ` hashType ` s, i. e. ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 `
186- * other ` digestType ` s, i. e. ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
187- * and ` length ` the length in chars
188- * ` [hash] ` the hash of ` options.content ` (Buffer) (by default it's the hex digest of the md4 hash)
189- * ` [<hashType>:hash:<digestType>:<length>] ` optionally one can configure
190- * other ` hashType ` s, i. e. ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 `
191- * other ` digestType ` s, i. e. ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
192- * and ` length ` the length in chars
193- * ` [N] ` the N-th match obtained from matching the current file name against ` options.regExp `
180+ - ` [ext] ` the extension of the resource
181+ - ` [name] ` the basename of the resource
182+ - ` [path] ` the path of the resource relative to the ` context ` query parameter or option.
183+ - ` [folder] ` the folder the resource is in
184+ - ` [query] ` the queryof the resource, i.e. ` ?foo=bar `
185+ - ` [emoji] ` a random emoji representation of ` options.content `
186+ - ` [emoji:<length>] ` same as above, but with a customizable number of emojis
187+ - ` [contenthash] ` the hash of ` options.content ` (Buffer) (by default it's the hex digest of the md4 hash)
188+ - ` [<hashType>:contenthash:<digestType>:<length>] ` optionally one can configure
189+ - other ` hashType ` s, i. e. ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 `
190+ - other ` digestType ` s, i. e. ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
191+ - and ` length ` the length in chars
192+ - ` [hash] ` the hash of ` options.content ` (Buffer) (by default it's the hex digest of the md4 hash)
193+ - ` [<hashType>:hash:<digestType>:<length>] ` optionally one can configure
194+ - other ` hashType ` s, i. e. ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 `
195+ - other ` digestType ` s, i. e. ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
196+ - and ` length ` the length in chars
197+ - ` [N] ` the N-th match obtained from matching the current file name against ` options.regExp `
194198
195199In loader context ` [hash] ` and ` [contenthash] ` are the same, but we recommend using ` [contenthash] ` for avoid misleading.
196200
197201Examples
198202
199- ``` javascript
203+ ``` javascript
200204// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
201205loaderUtils .interpolateName (loaderContext, " js/[hash].script.[ext]" , { content: ... });
202206// => js/9473fdd0d880a43c21b7778d34872157.script.js
@@ -247,28 +251,33 @@ loaderUtils.interpolateName(loaderContext, "script-[1].[ext]", { regExp: "page-(
247251// loaderContext.resourcePath = "/absolute/path/to/app/js/javascript.js"
248252// loaderContext.resourceQuery = "?foo=bar"
249253loaderUtils .interpolateName (
250- loaderContext,
251- (resourcePath , resourceQuery ) => {
254+ loaderContext,
255+ (resourcePath , resourceQuery ) => {
252256 // resourcePath - `/app/js/javascript.js`
253257 // resourceQuery - `?foo=bar`
254258
255- return " js/[hash].script.[ext]" ;
256- },
259+ return " js/[hash].script.[ext]" ;
260+ },
257261 { content: ... }
258262);
259263// => js/9473fdd0d880a43c21b7778d34872157.script.js
260264```
261265
262266### ` getHashDigest `
263267
264- ``` javascript
265- const digestString = loaderUtils .getHashDigest (buffer, hashType, digestType, maxLength);
268+ ``` javascript
269+ const digestString = loaderUtils .getHashDigest (
270+ buffer,
271+ hashType,
272+ digestType,
273+ maxLength
274+ );
266275```
267276
268- * ` buffer ` the content that should be hashed
269- * ` hashType ` one of ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 ` or any other node.js supported hash type
270- * ` digestType ` one of ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
271- * ` maxLength ` the maximum length in chars
277+ - ` buffer ` the content that should be hashed
278+ - ` hashType ` one of ` sha1 ` , ` md4 ` , ` md5 ` , ` sha256 ` , ` sha512 ` or any other node.js supported hash type
279+ - ` digestType ` one of ` hex ` , ` base26 ` , ` base32 ` , ` base36 ` , ` base49 ` , ` base52 ` , ` base58 ` , ` base62 ` , ` base64 `
280+ - ` maxLength ` the maximum length in chars
272281
273282## License
274283
0 commit comments