[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
---|
| 8 | const RuntimeModule = require("../RuntimeModule");
|
---|
| 9 | const Template = require("../Template");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("../Compilation")} Compilation */
|
---|
| 12 | /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
---|
| 13 |
|
---|
| 14 | class 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 |
|
---|
| 45 | module.exports = ChunkPreloadTriggerRuntimeModule;
|
---|