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

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

F4 Finalna Verzija

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