source: imaps-frontend/node_modules/webpack/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

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