MCPcopy
hub / github.com/webpack/webpack / getRelativePath

Function getRelativePath

lib/esm/ModuleChunkFormatPlugin.js:38–70  ·  view source on GitHub ↗
(compilation, chunk, runtimeChunk)

Source from the content-addressed store, hash-verified

36 * @returns {string} the relative path
37 */
38const getRelativePath = (compilation, chunk, runtimeChunk) => {
39 const currentOutputName = compilation
40 .getPath(
41 getChunkFilenameTemplate(runtimeChunk, compilation.outputOptions),
42 {
43 chunk: runtimeChunk,
44 contentHashType: "javascript"
45 }
46 )
47 .replace(/^\/+/g, "")
48 .split("/");
49 const baseOutputName = [...currentOutputName];
50 const chunkOutputName = compilation
51 .getPath(getChunkFilenameTemplate(chunk, compilation.outputOptions), {
52 chunk,
53 contentHashType: "javascript"
54 })
55 .replace(/^\/+/g, "")
56 .split("/");
57
58 // remove common parts except filename
59 while (
60 baseOutputName.length > 1 &&
61 chunkOutputName.length > 1 &&
62 baseOutputName[0] === chunkOutputName[0]
63 ) {
64 baseOutputName.shift();
65 chunkOutputName.shift();
66 }
67 const last = chunkOutputName.join("/");
68 // create final path
69 return getUndoPath(baseOutputName.join("/"), last, true) + last;
70};
71
72/**
73 * Renders chunk import.

Callers 1

renderChunkImportFunction · 0.85

Calls 4

getUndoPathFunction · 0.85
splitMethod · 0.80
getPathMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected