1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
10 | exports.markAsyncChunksNonInitial = void 0;
|
---|
11 | /**
|
---|
12 | * Webpack stats may incorrectly mark extra entry points `initial` chunks, when
|
---|
13 | * they are actually loaded asynchronously and thus not in the main bundle. This
|
---|
14 | * function finds extra entry points in Webpack stats and corrects this value
|
---|
15 | * whereever necessary. Does not modify {@param webpackStats}.
|
---|
16 | */
|
---|
17 | function markAsyncChunksNonInitial(webpackStats, extraEntryPoints) {
|
---|
18 | const { chunks = [], entrypoints: entryPoints = {} } = webpackStats;
|
---|
19 | // Find all Webpack chunk IDs not injected into the main bundle. We don't have
|
---|
20 | // to worry about transitive dependencies because extra entry points cannot be
|
---|
21 | // depended upon in Webpack, thus any extra entry point with `inject: false`,
|
---|
22 | // **cannot** be loaded in main bundle.
|
---|
23 | const asyncChunkIds = extraEntryPoints
|
---|
24 | .filter((entryPoint) => !entryPoint.inject && entryPoints[entryPoint.bundleName])
|
---|
25 | .flatMap((entryPoint) => { var _a; return (_a = entryPoints[entryPoint.bundleName].chunks) === null || _a === void 0 ? void 0 : _a.filter((n) => n !== 'runtime'); });
|
---|
26 | // Find chunks for each ID.
|
---|
27 | const asyncChunks = asyncChunkIds.map((chunkId) => {
|
---|
28 | const chunk = chunks.find((chunk) => chunk.id === chunkId);
|
---|
29 | if (!chunk) {
|
---|
30 | throw new Error(`Failed to find chunk (${chunkId}) in set:\n${JSON.stringify(chunks)}`);
|
---|
31 | }
|
---|
32 | return chunk;
|
---|
33 | });
|
---|
34 | // A chunk is considered `initial` only if Webpack already belives it to be initial
|
---|
35 | // and the application developer did not mark it async via an extra entry point.
|
---|
36 | return chunks.map((chunk) => {
|
---|
37 | return asyncChunks.find((asyncChunk) => asyncChunk === chunk)
|
---|
38 | ? {
|
---|
39 | ...chunk,
|
---|
40 | initial: false,
|
---|
41 | }
|
---|
42 | : chunk;
|
---|
43 | });
|
---|
44 | }
|
---|
45 | exports.markAsyncChunksNonInitial = markAsyncChunksNonInitial;
|
---|