source: trip-planner-front/node_modules/webpack/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js@ 188ee53

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

initial commit

  • Property mode set to 100644
File size: 1.1 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 ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
14 /**
15 * @param {Record<string|number, (string|number)[]>} chunkMap map from chunk to chunks
16 */
17 constructor(chunkMap) {
18 super(`chunk preload 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.preloadChunk});`
31 ];
32 return Template.asString([
33 Template.asString([
34 `var chunkToChildrenMap = ${JSON.stringify(chunkMap, null, "\t")};`,
35 `${
36 RuntimeGlobals.ensureChunkHandlers
37 }.preload = ${runtimeTemplate.basicFunction("chunkId", body)};`
38 ])
39 ]);
40 }
41}
42
43module.exports = ChunkPreloadTriggerRuntimeModule;
Note: See TracBrowser for help on using the repository browser.