1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const RuntimeGlobals = require("../RuntimeGlobals");
|
8 | const RuntimeModule = require("../RuntimeModule");
|
9 |
|
10 |
|
11 |
|
12 | class StartupEntrypointRuntimeModule extends RuntimeModule {
|
13 | constructor(asyncChunkLoading) {
|
14 | super("startup entrypoint");
|
15 | this.asyncChunkLoading = asyncChunkLoading;
|
16 | }
|
17 |
|
18 | |
19 |
|
20 |
|
21 | generate() {
|
22 | const { compilation } = this;
|
23 | const { runtimeTemplate } = compilation;
|
24 | return `${
|
25 | RuntimeGlobals.startupEntrypoint
|
26 | } = ${runtimeTemplate.basicFunction("result, chunkIds, fn", [
|
27 | "// arguments: chunkIds, moduleId are deprecated",
|
28 | "var moduleId = chunkIds;",
|
29 | `if(!fn) chunkIds = result, fn = ${runtimeTemplate.returningFunction(
|
30 | `__webpack_require__(${RuntimeGlobals.entryModuleId} = moduleId)`
|
31 | )};`,
|
32 | ...(this.asyncChunkLoading
|
33 | ? [
|
34 | `return Promise.all(chunkIds.map(${
|
35 | RuntimeGlobals.ensureChunk
|
36 | }, __webpack_require__)).then(${runtimeTemplate.basicFunction("", [
|
37 | "var r = fn();",
|
38 | "return r === undefined ? result : r;"
|
39 | ])})`
|
40 | ]
|
41 | : [
|
42 | `chunkIds.map(${RuntimeGlobals.ensureChunk}, __webpack_require__)`,
|
43 | "var r = fn();",
|
44 | "return r === undefined ? result : r;"
|
45 | ])
|
46 | ])}`;
|
47 | }
|
48 | }
|
49 |
|
50 | module.exports = StartupEntrypointRuntimeModule;
|