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

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.7 KB
Line 
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("../Chunk")} Chunk */
12/** @typedef {import("../Chunk").ChunkChildOfTypeInOrder} ChunkChildOfTypeInOrder */
13/** @typedef {import("../Compilation")} Compilation */
14
15class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
16 /**
17 * @param {ChunkChildOfTypeInOrder[]} startupChunks chunk ids to trigger when chunks are loaded
18 */
19 constructor(startupChunks) {
20 super("startup prefetch", RuntimeModule.STAGE_TRIGGER);
21 /** @type {ChunkChildOfTypeInOrder[]} */
22 this.startupChunks = startupChunks;
23 }
24
25 /**
26 * Generates runtime code for this runtime module.
27 * @returns {string | null} runtime code
28 */
29 generate() {
30 const { startupChunks } = this;
31 const compilation = /** @type {Compilation} */ (this.compilation);
32 const chunk = /** @type {Chunk} */ (this.chunk);
33 const { runtimeTemplate } = compilation;
34 return Template.asString(
35 startupChunks.map(
36 ({ onChunks, chunks }) =>
37 `${RuntimeGlobals.onChunksLoaded}(0, ${JSON.stringify(
38 // This need to include itself to delay execution after this chunk has been fully loaded
39 onChunks.filter((c) => c === chunk).map((c) => c.id)
40 )}, ${runtimeTemplate.basicFunction(
41 "",
42 chunks.size < 3
43 ? Array.from(
44 chunks,
45 (c) =>
46 `${RuntimeGlobals.prefetchChunk}(${JSON.stringify(c.id)});`
47 )
48 : `${JSON.stringify(Array.from(chunks, (c) => c.id))}.map(${
49 RuntimeGlobals.prefetchChunk
50 });`
51 )}, 5);`
52 )
53 );
54 }
55}
56
57module.exports = ChunkPrefetchStartupRuntimeModule;
Note: See TracBrowser for help on using the repository browser.