source: trip-planner-front/node_modules/webpack/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js@ 84d0fbb

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

initial commit

  • Property mode set to 100644
File size: 1.3 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("../RuntimeTemplate")} RuntimeTemplate */
12
13class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
14 /**
15 * @param {Record<string|number, (string|number)[]>} chunkMap map from chunk to
16 */
17 constructor(chunkMap) {
18 super(`chunk prefetch trigger`, RuntimeModule.STAGE_TRIGGER);
19 this.chunkMap = chunkMap;
20 }
21
22 /**
23 * @returns {string} runtime code
24 */
25 generate() {
26 const { chunkMap } = this;
27 const { runtimeTemplate } = this.compilation;
28 const body = [
29 "var chunks = chunkToChildrenMap[chunkId];",
30 `Array.isArray(chunks) && chunks.map(${RuntimeGlobals.prefetchChunk});`
31 ];
32 return Template.asString([
33 Template.asString([
34 `var chunkToChildrenMap = ${JSON.stringify(chunkMap, null, "\t")};`,
35 `${
36 RuntimeGlobals.ensureChunkHandlers
37 }.prefetch = ${runtimeTemplate.expressionFunction(
38 `Promise.all(promises).then(${runtimeTemplate.basicFunction(
39 "",
40 body
41 )})`,
42 "chunkId, promises"
43 )};`
44 ])
45 ]);
46 }
47}
48
49module.exports = ChunkPrefetchTriggerRuntimeModule;
Note: See TracBrowser for help on using the repository browser.