source: frontend/node_modules/webpack/lib/runtime/StartupChunkDependenciesRuntimeModule.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RuntimeGlobals = require("../RuntimeGlobals");
9const RuntimeModule = require("../RuntimeModule");
10const Template = require("../Template");
11
12/** @typedef {import("../Chunk")} Chunk */
13/** @typedef {import("../ChunkGraph")} ChunkGraph */
14/** @typedef {import("../Compilation")} Compilation */
15
16class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
17 /**
18 * @param {boolean} asyncChunkLoading use async chunk loading
19 */
20 constructor(asyncChunkLoading) {
21 super("startup chunk dependencies", RuntimeModule.STAGE_TRIGGER);
22 /** @type {boolean} */
23 this.asyncChunkLoading = asyncChunkLoading;
24 }
25
26 /**
27 * Generates runtime code for this runtime module.
28 * @returns {string | null} runtime code
29 */
30 generate() {
31 const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
32 const chunk = /** @type {Chunk} */ (this.chunk);
33 const chunkIds = [
34 ...chunkGraph.getChunkEntryDependentChunksIterable(chunk)
35 ].map((chunk) => chunk.id);
36 const compilation = /** @type {Compilation} */ (this.compilation);
37 const { runtimeTemplate } = compilation;
38 return Template.asString([
39 `var next = ${RuntimeGlobals.startup};`,
40 `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
41 "",
42 !this.asyncChunkLoading
43 ? [
44 ...chunkIds.map(
45 (id) => `${RuntimeGlobals.ensureChunk}(${JSON.stringify(id)});`
46 ),
47 "return next();"
48 ]
49 : chunkIds.length === 1
50 ? `return ${RuntimeGlobals.ensureChunk}(${JSON.stringify(
51 chunkIds[0]
52 )}).then(next);`
53 : chunkIds.length > 2
54 ? [
55 // using map is shorter for 3 or more chunks
56 `return Promise.all(${JSON.stringify(chunkIds)}.map(${
57 RuntimeGlobals.ensureChunk
58 }, ${RuntimeGlobals.require})).then(next);`
59 ]
60 : [
61 // calling ensureChunk directly is shorter for 0 - 2 chunks
62 "return Promise.all([",
63 Template.indent(
64 chunkIds
65 .map(
66 (id) =>
67 `${RuntimeGlobals.ensureChunk}(${JSON.stringify(id)})`
68 )
69 .join(",\n")
70 ),
71 "]).then(next);"
72 ]
73 )};`
74 ]);
75 }
76}
77
78module.exports = StartupChunkDependenciesRuntimeModule;
Note: See TracBrowser for help on using the repository browser.