MCPcopy
hub / github.com/webpack/webpack / resolveChunkUrlSentinels

Method resolveChunkUrlSentinels

lib/html/HtmlGenerator.js:78–121  ·  view source on GitHub ↗

* Replace every `makeChunkUrlSentinel` sentinel in `content` with * `${PUBLIC_PATH_AUTO}<chunkFilename>`. Must run after * `Compilation#createHash()` so `[contenthash]` resolves. * @param {string} content content * @param {Compilation} compilation compilation * @returns {string} resolved c

(content, compilation)

Source from the content-addressed store, hash-verified

76 * @returns {string} resolved content
77 */
78 static resolveChunkUrlSentinels(content, compilation) {
79 if (!content.includes("__WEBPACK_HTML_CHUNK_URL__")) return content;
80 const outputOptions = compilation.outputOptions;
81 let chunksById = chunksByIdCache.get(compilation);
82 if (chunksById === undefined) {
83 chunksById = new Map();
84 for (const chunk of compilation.chunks) {
85 chunksById.set(String(chunk.id), chunk);
86 }
87 chunksByIdCache.set(compilation, chunksById);
88 }
89 return content.replace(
90 CHUNK_URL_SENTINEL_REGEXP,
91 (_, hexId, contentHashType) => {
92 const chunkId = Buffer.from(hexId, "hex").toString("utf8");
93 const chunk = chunksById.get(chunkId);
94 if (!chunk) return "data:,";
95 let filenameTemplate;
96 if (contentHashType === "css") {
97 const CssModulesPlugin = require("../css/CssModulesPlugin");
98
99 filenameTemplate = CssModulesPlugin.getChunkFilenameTemplate(
100 chunk,
101 outputOptions
102 );
103 } else {
104 filenameTemplate =
105 chunk.filenameTemplate ||
106 (chunk.canBeInitial()
107 ? outputOptions.filename
108 : outputOptions.chunkFilename);
109 }
110 const filename = compilation.getPath(
111 /** @type {import("../TemplatedPathPlugin").TemplatePath} */
112 (filenameTemplate),
113 {
114 chunk,
115 contentHashType
116 }
117 );
118 return `${PUBLIC_PATH_AUTO}${filename}`;
119 }
120 );
121 }
122
123 /**
124 * Creates an instance of HtmlGenerator.

Callers 1

applyMethod · 0.80

Calls 8

canBeInitialMethod · 0.80
getPathMethod · 0.80
requireFunction · 0.50
getMethod · 0.45
setMethod · 0.45
replaceMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected