MCPcopy
hub / github.com/webpack/webpack / getAssetPathWithInfo

Method getAssetPathWithInfo

lib/asset/AssetGenerator.js:353–428  ·  view source on GitHub ↗

* Gets asset path with info. * @param {NormalModule} module module for which the code should be generated * @param {Pick<AssetResourceGeneratorOptions, "publicPath">} generatorOptions generator options * @param {GenerateContext} generateContext context for generate * @param {string} filename

(
		module,
		generatorOptions,
		{ runtime, runtimeTemplate, type, chunkGraph, runtimeRequirements },
		filename,
		assetInfo,
		contentHash,
		fullContentHash
	)

Source from the content-addressed store, hash-verified

351 * @returns {{ assetPath: string, assetInfo: AssetInfo }} asset path and info
352 */
353 static getAssetPathWithInfo(
354 module,
355 generatorOptions,
356 { runtime, runtimeTemplate, type, chunkGraph, runtimeRequirements },
357 filename,
358 assetInfo,
359 contentHash,
360 fullContentHash
361 ) {
362 const sourceFilename = AssetGenerator.getSourceFileName(
363 module,
364 runtimeTemplate
365 );
366
367 /** @type {undefined | string} */
368 let assetPath;
369
370 if (generatorOptions.publicPath !== undefined && type === JAVASCRIPT_TYPE) {
371 const { path, info } = runtimeTemplate.compilation.getAssetPathWithInfo(
372 generatorOptions.publicPath,
373 {
374 module,
375 runtime,
376 filename: sourceFilename,
377 chunkGraph,
378 contentHash,
379 contentHashFull: fullContentHash
380 }
381 );
382 assetInfo = mergeAssetInfo(assetInfo, info);
383 assetPath = JSON.stringify(path + filename);
384 } else if (
385 generatorOptions.publicPath !== undefined &&
386 type === ASSET_URL_TYPE
387 ) {
388 const { path, info } = runtimeTemplate.compilation.getAssetPathWithInfo(
389 generatorOptions.publicPath,
390 {
391 module,
392 runtime,
393 filename: sourceFilename,
394 chunkGraph,
395 contentHash,
396 contentHashFull: fullContentHash
397 }
398 );
399 assetInfo = mergeAssetInfo(assetInfo, info);
400 assetPath = path + filename;
401 } else if (type === JAVASCRIPT_TYPE) {
402 // add __webpack_require__.p
403 runtimeRequirements.add(RuntimeGlobals.publicPath);
404 assetPath = runtimeTemplate.concatenation(
405 { expr: RuntimeGlobals.publicPath },
406 filename
407 );
408 } else if (type === ASSET_URL_TYPE) {
409 const compilation = runtimeTemplate.compilation;
410 const path =

Callers 3

getFilenameWithInfoMethod · 0.45
generateMethod · 0.45
updateHashMethod · 0.45

Calls 6

mergeAssetInfoFunction · 0.85
getSourceFileNameMethod · 0.80
concatenationMethod · 0.80
getAssetPathMethod · 0.80
sliceMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected