( loaderContext, localIdentName, localName, options, )
| 277 | } |
| 278 | |
| 279 | function defaultGetLocalIdent( |
| 280 | loaderContext, |
| 281 | localIdentName, |
| 282 | localName, |
| 283 | options, |
| 284 | ) { |
| 285 | const { context, hashSalt, hashStrategy } = options; |
| 286 | const { resourcePath } = loaderContext; |
| 287 | let relativeResourcePath = normalizePath( |
| 288 | path.relative(context, resourcePath), |
| 289 | ); |
| 290 | |
| 291 | // eslint-disable-next-line no-underscore-dangle |
| 292 | if (loaderContext._module && loaderContext._module.matchResource) { |
| 293 | relativeResourcePath = `${normalizePath( |
| 294 | // eslint-disable-next-line no-underscore-dangle |
| 295 | path.relative(context, loaderContext._module.matchResource), |
| 296 | )}`; |
| 297 | } |
| 298 | |
| 299 | // eslint-disable-next-line no-param-reassign |
| 300 | options.content = |
| 301 | hashStrategy === "minimal-subset" && /\[local\]/.test(localIdentName) |
| 302 | ? relativeResourcePath |
| 303 | : `${relativeResourcePath}\x00${localName}`; |
| 304 | |
| 305 | let { hashFunction, hashDigest, hashDigestLength } = options; |
| 306 | const matches = localIdentName.match( |
| 307 | /\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i, |
| 308 | ); |
| 309 | |
| 310 | if (matches) { |
| 311 | const hashName = matches[2] || hashFunction; |
| 312 | |
| 313 | hashFunction = matches[1] || hashFunction; |
| 314 | hashDigest = matches[3] || hashDigest; |
| 315 | hashDigestLength = matches[4] || hashDigestLength; |
| 316 | |
| 317 | // `hash` and `contenthash` are same in `loader-utils` context |
| 318 | // let's keep `hash` for backward compatibility |
| 319 | |
| 320 | // eslint-disable-next-line no-param-reassign |
| 321 | localIdentName = localIdentName.replace( |
| 322 | /\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, |
| 323 | () => (hashName === "fullhash" ? "[fullhash]" : "[contenthash]"), |
| 324 | ); |
| 325 | } |
| 326 | |
| 327 | let localIdentHash = ""; |
| 328 | |
| 329 | for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) { |
| 330 | const hash = ( |
| 331 | loaderContext.utils.createHash || |
| 332 | // TODO remove in the next major release |
| 333 | // eslint-disable-next-line no-underscore-dangle |
| 334 | loaderContext._compiler.webpack.util.createHash |
| 335 | )(hashFunction); |
| 336 |
no test coverage detected