source: imaps-frontend/node_modules/webpack/lib/runtime/EnsureChunkRuntimeModule.js

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

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.2 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("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
13
14class EnsureChunkRuntimeModule extends RuntimeModule {
15 /**
16 * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
17 */
18 constructor(runtimeRequirements) {
19 super("ensure chunk");
20 this.runtimeRequirements = runtimeRequirements;
21 }
22
23 /**
24 * @returns {string | null} runtime code
25 */
26 generate() {
27 const compilation = /** @type {Compilation} */ (this.compilation);
28 const { runtimeTemplate } = compilation;
29 // Check if there are non initial chunks which need to be imported using require-ensure
30 if (this.runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)) {
31 const withFetchPriority = this.runtimeRequirements.has(
32 RuntimeGlobals.hasFetchPriority
33 );
34 const handlers = RuntimeGlobals.ensureChunkHandlers;
35 return Template.asString([
36 `${handlers} = {};`,
37 "// This file contains only the entry chunk.",
38 "// The chunk loading function for additional chunks",
39 `${RuntimeGlobals.ensureChunk} = ${runtimeTemplate.basicFunction(
40 `chunkId${withFetchPriority ? ", fetchPriority" : ""}`,
41 [
42 `return Promise.all(Object.keys(${handlers}).reduce(${runtimeTemplate.basicFunction(
43 "promises, key",
44 [
45 `${handlers}[key](chunkId, promises${
46 withFetchPriority ? ", fetchPriority" : ""
47 });`,
48 "return promises;"
49 ]
50 )}, []));`
51 ]
52 )};`
53 ]);
54 }
55 // There ensureChunk is used somewhere in the tree, so we need an empty requireEnsure
56 // function. This can happen with multiple entrypoints.
57 return Template.asString([
58 "// The chunk loading function for additional chunks",
59 "// Since all referenced chunks are already included",
60 "// in this file, this function is empty here.",
61 `${RuntimeGlobals.ensureChunk} = ${runtimeTemplate.returningFunction(
62 "Promise.resolve()"
63 )};`
64 ]);
65 }
66}
67
68module.exports = EnsureChunkRuntimeModule;
Note: See TracBrowser for help on using the repository browser.