From c43ace73835fb2a21f3ff3eceec4e44e05937d72 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 7 Jun 2021 11:33:16 +0200 Subject: [PATCH] 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 --- .../build_angular/src/browser/index.ts | 35 ++++++++----------- .../src/webpack/utils/async-chunks.ts | 16 ++++++--- .../build_angular/src/webpack/utils/stats.ts | 3 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/browser/index.ts b/packages/angular_devkit/build_angular/src/browser/index.ts index 970d2233e9b6..1daaeec0026a 100644 --- a/packages/angular_devkit/build_angular/src/browser/index.ts +++ b/packages/angular_devkit/build_angular/src/browser/index.ts @@ -143,25 +143,21 @@ async function initialize( // Assets are processed directly by the builder except when watching const adjustedOptions = options.watch ? options : { ...options, assets: [] }; - const { - config, - projectRoot, - projectSourceRoot, - i18n, - } = await generateI18nBrowserWebpackConfigFromContext( - adjustedOptions, - context, - (wco) => [ - getCommonConfig(wco), - getBrowserConfig(wco), - getStylesConfig(wco), - getStatsConfig(wco), - getAnalyticsConfig(wco, context), - getCompilerConfig(wco), - wco.buildOptions.webWorkerTsConfig ? getWorkerConfig(wco) : {}, - ], - { differentialLoadingNeeded }, - ); + const { config, projectRoot, projectSourceRoot, i18n } = + await generateI18nBrowserWebpackConfigFromContext( + adjustedOptions, + context, + (wco) => [ + getCommonConfig(wco), + getBrowserConfig(wco), + getStylesConfig(wco), + getStatsConfig(wco), + getAnalyticsConfig(wco, context), + getCompilerConfig(wco), + wco.buildOptions.webWorkerTsConfig ? getWorkerConfig(wco) : {}, + ], + { differentialLoadingNeeded }, + ); // Validate asset option values if processed directly if (options.assets?.length && !adjustedOptions.assets?.length) { @@ -803,7 +799,6 @@ function generateBundleInfoStats( size: bundle.size, files: bundle.map ? [bundle.filename, bundle.map.filename] : [bundle.filename], names: chunk?.names, - entry: !!chunk?.names?.includes('runtime'), initial: !!chunk?.initial, rendered: true, chunkType, diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts b/packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts index f8c8786396c9..af410c931619 100644 --- a/packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts +++ b/packages/angular_devkit/build_angular/src/webpack/utils/async-chunks.ts @@ -27,7 +27,9 @@ export function markAsyncChunksNonInitial( // **cannot** be loaded in main bundle. const asyncChunkIds = extraEntryPoints .filter((entryPoint) => !entryPoint.inject) - .flatMap((entryPoint) => entryPoints[entryPoint.bundleName].chunks); + .flatMap((entryPoint) => + entryPoints[entryPoint.bundleName].chunks?.filter((n) => n !== 'runtime'), + ); // Find chunks for each ID. const asyncChunks = asyncChunkIds.map((chunkId) => { @@ -41,8 +43,12 @@ export function markAsyncChunksNonInitial( // A chunk is considered `initial` only if Webpack already belives it to be initial // and the application developer did not mark it async via an extra entry point. - return chunks.map((chunk) => ({ - ...chunk, - initial: chunk.initial && !asyncChunks.find((asyncChunk) => asyncChunk === chunk), - })); + return chunks.map((chunk) => { + return asyncChunks.find((asyncChunk) => asyncChunk === chunk) + ? { + ...chunk, + initial: false, + } + : chunk; + }); } diff --git a/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts b/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts index 316c0105cabd..a6f59294e521 100644 --- a/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts +++ b/packages/angular_devkit/build_angular/src/webpack/utils/stats.ts @@ -45,7 +45,6 @@ export function generateBundleStats(info: { size?: number; files?: string[]; names?: string[]; - entry?: boolean; initial?: boolean; rendered?: boolean; chunkType?: ChunkType; @@ -57,7 +56,7 @@ export function generateBundleStats(info: { .map((f) => path.basename(f)) .join(', ') ?? ''; const names = info.names?.length ? info.names.join(', ') : '-'; - const initial = !!(info.entry || info.initial); + const initial = !!info.initial; const chunkType = info.chunkType || 'unknown'; return {