Skip to content

Commit 3fcf318

Browse files
committed
fix(@angular-devkit/build-angular): add web-workers in lazy chunks in stats output
Web-workers are not marked as `initial` since their initialization can be guarded. Closes #21059 (cherry picked from commit c43ace7)
1 parent 83a9c46 commit 3fcf318

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,21 @@ async function initialize(
143143
// Assets are processed directly by the builder except when watching
144144
const adjustedOptions = options.watch ? options : { ...options, assets: [] };
145145

146-
const {
147-
config,
148-
projectRoot,
149-
projectSourceRoot,
150-
i18n,
151-
} = await generateI18nBrowserWebpackConfigFromContext(
152-
adjustedOptions,
153-
context,
154-
(wco) => [
155-
getCommonConfig(wco),
156-
getBrowserConfig(wco),
157-
getStylesConfig(wco),
158-
getStatsConfig(wco),
159-
getAnalyticsConfig(wco, context),
160-
getCompilerConfig(wco),
161-
wco.buildOptions.webWorkerTsConfig ? getWorkerConfig(wco) : {},
162-
],
163-
{ differentialLoadingNeeded },
164-
);
146+
const { config, projectRoot, projectSourceRoot, i18n } =
147+
await generateI18nBrowserWebpackConfigFromContext(
148+
adjustedOptions,
149+
context,
150+
(wco) => [
151+
getCommonConfig(wco),
152+
getBrowserConfig(wco),
153+
getStylesConfig(wco),
154+
getStatsConfig(wco),
155+
getAnalyticsConfig(wco, context),
156+
getCompilerConfig(wco),
157+
wco.buildOptions.webWorkerTsConfig ? getWorkerConfig(wco) : {},
158+
],
159+
{ differentialLoadingNeeded },
160+
);
165161

166162
// Validate asset option values if processed directly
167163
if (options.assets?.length && !adjustedOptions.assets?.length) {
@@ -803,7 +799,6 @@ function generateBundleInfoStats(
803799
size: bundle.size,
804800
files: bundle.map ? [bundle.filename, bundle.map.filename] : [bundle.filename],
805801
names: chunk?.names,
806-
entry: !!chunk?.names?.includes('runtime'),
807802
initial: !!chunk?.initial,
808803
rendered: true,
809804
chunkType,

packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export function markAsyncChunksNonInitial(
2727
// **cannot** be loaded in main bundle.
2828
const asyncChunkIds = extraEntryPoints
2929
.filter((entryPoint) => !entryPoint.inject)
30-
.flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks);
30+
.flatMap((entryPoint) =>
31+
entryPoints[entryPoint.bundleName].chunks?.filter((n) => n !== 'runtime'),
32+
);
3133

3234
// Find chunks for each ID.
3335
const asyncChunks = asyncChunkIds.map((chunkId) => {
@@ -41,8 +43,12 @@ export function markAsyncChunksNonInitial(
4143

4244
// A chunk is considered `initial` only if Webpack already belives it to be initial
4345
// and the application developer did not mark it async via an extra entry point.
44-
return chunks.map((chunk) => ({
45-
...chunk,
46-
initial: chunk.initial && !asyncChunks.find((asyncChunk) => asyncChunk === chunk),
47-
}));
46+
return chunks.map((chunk) => {
47+
return asyncChunks.find((asyncChunk) => asyncChunk === chunk)
48+
? {
49+
...chunk,
50+
initial: false,
51+
}
52+
: chunk;
53+
});
4854
}

packages/angular_devkit/build_angular/src/webpack/utils/stats.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export function generateBundleStats(info: {
4545
size?: number;
4646
files?: string[];
4747
names?: string[];
48-
entry?: boolean;
4948
initial?: boolean;
5049
rendered?: boolean;
5150
chunkType?: ChunkType;
@@ -57,7 +56,7 @@ export function generateBundleStats(info: {
5756
.map((f) => path.basename(f))
5857
.join(', ') ?? '';
5958
const names = info.names?.length ? info.names.join(', ') : '-';
60-
const initial = !!(info.entry || info.initial);
59+
const initial = !!info.initial;
6160
const chunkType = info.chunkType || 'unknown';
6261

6362
return {

0 commit comments

Comments
 (0)