source: imaps-frontend/node_modules/webpack/lib/runtime/StartupChunkDependenciesRuntimeModule.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: 2.2 KB
RevLine 
[79a0317]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 this.asyncChunkLoading = asyncChunkLoading;
23 }
24
25 /**
26 * @returns {string | null} runtime code
27 */
28 generate() {
29 const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
30 const chunk = /** @type {Chunk} */ (this.chunk);
31 const chunkIds = Array.from(
32 chunkGraph.getChunkEntryDependentChunksIterable(chunk)
33 ).map(chunk => chunk.id);
34 const compilation = /** @type {Compilation} */ (this.compilation);
35 const { runtimeTemplate } = compilation;
36 return Template.asString([
37 `var next = ${RuntimeGlobals.startup};`,
38 `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
39 "",
40 !this.asyncChunkLoading
41 ? chunkIds
42 .map(
43 id => `${RuntimeGlobals.ensureChunk}(${JSON.stringify(id)});`
44 )
45 .concat("return next();")
46 : chunkIds.length === 1
47 ? `return ${RuntimeGlobals.ensureChunk}(${JSON.stringify(
48 chunkIds[0]
49 )}).then(next);`
50 : chunkIds.length > 2
51 ? [
52 // using map is shorter for 3 or more chunks
53 `return Promise.all(${JSON.stringify(chunkIds)}.map(${
54 RuntimeGlobals.ensureChunk
55 }, ${RuntimeGlobals.require})).then(next);`
56 ]
57 : [
58 // calling ensureChunk directly is shorter for 0 - 2 chunks
59 "return Promise.all([",
60 Template.indent(
61 chunkIds
62 .map(
63 id =>
64 `${RuntimeGlobals.ensureChunk}(${JSON.stringify(id)})`
65 )
66 .join(",\n")
67 ),
68 "]).then(next);"
69 ]
70 )};`
71 ]);
72 }
73}
74
75module.exports = StartupChunkDependenciesRuntimeModule;
Note: See TracBrowser for help on using the repository browser.