MCPcopy Index your code
hub / github.com/webpack/css-loader / defaultGetLocalIdent

Function defaultGetLocalIdent

src/utils.js:279–404  ·  view source on GitHub ↗
(
  loaderContext,
  localIdentName,
  localName,
  options,
)

Source from the content-addressed store, hash-verified

277}
278
279function 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

Callers 1

generateScopedNameFunction · 0.85

Calls 1

normalizePathFunction · 0.85

Tested by

no test coverage detected