source: trip-planner-front/node_modules/webpack/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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