MCPcopy
hub / github.com/webpack/webpack / _renderHtml

Method _renderHtml

lib/html/HtmlGenerator.js:381–407  ·  view source on GitHub ↗

* Run all HTML dependency templates against the original module source and * return the rewritten HTML. When `undoPath` is a string, `[webpack/auto]` * placeholders left in by asset/url dependencies are resolved to that * undo path (use `""` to make URLs root-relative). When `undoPath` is *

(module, generateContext, undoPath)

Source from the content-addressed store, hash-verified

379 * @returns {string} the rewritten HTML
380 */
381 _renderHtml(module, generateContext, undoPath) {
382 // The dependency-template pass is identical for both type passes (no
383 // template branches on `type` or writes `runtimeRequirements`), so
384 // compute the raw render once per `codeGeneration()` and reuse it; the
385 // passes diverge only in the `[webpack/auto]` substitution below.
386 const cacheKey = generateContext.runtimeRequirements;
387 let rawContent = this._rawRenderCache.get(cacheKey);
388 if (rawContent === undefined) {
389 const originalSource = /** @type {Source} */ (module.originalSource());
390 const source = new ReplaceSource(originalSource);
391 /** @type {InitFragment<GenerateContext>[]} */
392 const initFragments = [];
393
394 this.sourceModule(module, initFragments, source, generateContext);
395 rawContent = /** @type {string} */ (source.source());
396 this._rawRenderCache.set(cacheKey, rawContent);
397 }
398
399 if (undoPath === undefined) {
400 // HTML output — leave sentinels and `[webpack/auto]` for renderManifest.
401 return rawContent;
402 }
403
404 // JS-export path — resolve `[webpack/auto]` inline; chunk-URL sentinels
405 // stay for `HtmlModulesPlugin`'s `JavascriptModulesPlugin.render` tap.
406 return rawContent.split(PUBLIC_PATH_AUTO).join(undoPath);
407 }
408
409 /**
410 * Generates generated code for this runtime module.

Callers 1

generateMethod · 0.95

Calls 6

sourceModuleMethod · 0.95
sourceMethod · 0.80
splitMethod · 0.80
getMethod · 0.45
originalSourceMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected