source: frontend/node_modules/webpack/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[9af201e]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const RuntimeGlobals = require("../RuntimeGlobals");
8const RuntimeModule = require("../RuntimeModule");
9const Template = require("../Template");
10
11/** @typedef {import("../Compilation")} Compilation */
12/** @typedef {import("../Chunk").ChunkChildIdsByOrdersMap} ChunkChildIdsByOrdersMap */
13
14class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
15 /**
16 * @param {ChunkChildIdsByOrdersMap} chunkMap map from chunk to
17 */
18 constructor(chunkMap) {
19 super("chunk prefetch trigger", RuntimeModule.STAGE_TRIGGER);
20 /** @type {ChunkChildIdsByOrdersMap} */
21 this.chunkMap = chunkMap;
22 }
23
24 /**
25 * Generates runtime code for this runtime module.
26 * @returns {string | null} runtime code
27 */
28 generate() {
29 const { chunkMap } = this;
30 const compilation = /** @type {Compilation} */ (this.compilation);
31 const { runtimeTemplate } = compilation;
32 const body = [
33 "var chunks = chunkToChildrenMap[chunkId];",
34 `Array.isArray(chunks) && chunks.map(${RuntimeGlobals.prefetchChunk});`
35 ];
36 return Template.asString([
37 Template.asString([
38 `var chunkToChildrenMap = ${JSON.stringify(chunkMap, null, "\t")};`,
39 `${
40 RuntimeGlobals.ensureChunkHandlers
41 }.prefetch = ${runtimeTemplate.expressionFunction(
42 // Prefetch is best-effort; silence rejections so a failed chunk
43 // load (e.g. chunkLoadTimeout) doesn't surface as an unhandled
44 // rejection through this dangling Promise.all chain.
45 `Promise.all(promises).then(${runtimeTemplate.basicFunction(
46 "",
47 body
48 )}, ${runtimeTemplate.basicFunction("", "")})`,
49 "chunkId, promises"
50 )};`
51 ])
52 ]);
53 }
54}
55
56module.exports = ChunkPrefetchTriggerRuntimeModule;
Note: See TracBrowser for help on using the repository browser.