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