Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): correctly mark async chunks as no…
Browse files Browse the repository at this point in the history
…n initial in dev-server
  • Loading branch information
alan-agius4 committed Jun 7, 2021
1 parent 699802d commit 2d0d82b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export function serveWebpackBrowser(
}

return runWebpackDevServer(webpackConfig, context, {
logging: transforms.logging || createWebpackLoggingCallback(!!options.verbose, logger),
logging: transforms.logging || createWebpackLoggingCallback(browserOptions, logger),
webpackFactory: require('webpack') as typeof webpack,
webpackDevServerFactory: require('webpack-dev-server') as typeof webpackDevServer,
}).pipe(
Expand Down
45 changes: 23 additions & 22 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,29 @@ export async function execute(
let useLegacyIds = true;

const ivyMessages: LocalizeMessage[] = [];
const { config, projectRoot } = await generateBrowserWebpackConfigFromContext(
{
...browserOptions,
optimization: false,
sourceMap: {
scripts: true,
styles: false,
vendor: true,
},
buildOptimizer: false,
aot: true,
progress: options.progress,
budgets: [],
assets: [],
scripts: [],
styles: [],
deleteOutputPath: false,
extractLicenses: false,
subresourceIntegrity: false,
outputHashing: OutputHashing.None,
namedChunks: true,
const builderOptions = {
...browserOptions,
optimization: false,
sourceMap: {
scripts: true,
styles: false,
vendor: true,
},
buildOptimizer: false,
aot: true,
progress: options.progress,
budgets: [],
assets: [],
scripts: [],
styles: [],
deleteOutputPath: false,
extractLicenses: false,
subresourceIntegrity: false,
outputHashing: OutputHashing.None,
namedChunks: true,
};
const { config, projectRoot } = await generateBrowserWebpackConfigFromContext(
builderOptions,
context,
(wco) => {
if (wco.tsConfig.options.enableIvy === false) {
Expand Down Expand Up @@ -262,7 +263,7 @@ export async function execute(
(await transforms?.webpackConfiguration?.(config)) || config,
context,
{
logging: createWebpackLoggingCallback(false, context.logger),
logging: createWebpackLoggingCallback(builderOptions, context.logger),
webpackFactory: webpack,
},
).toPromise();
Expand Down
19 changes: 17 additions & 2 deletions packages/angular_devkit/build_angular/src/webpack/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import { logging, tags } from '@angular-devkit/core';
import * as path from 'path';
import * as textTable from 'text-table';
import { Configuration, StatsCompilation } from 'webpack';
import { Schema as BrowserBuilderOptions } from '../../browser/schema';
import { colors as ansiColors, removeColor } from '../../utils/color';
import { getWebpackStatsConfig } from '../configs/stats';
import { markAsyncChunksNonInitial } from './async-chunks';
import { normalizeExtraEntryPoints } from './helpers';

export function formatSize(size: number): string {
if (size <= 0) {
Expand Down Expand Up @@ -325,15 +328,27 @@ export function statsHasWarnings(json: StatsCompilation): boolean {
}

export function createWebpackLoggingCallback(
verbose: boolean,
options: BrowserBuilderOptions,
logger: logging.LoggerApi,
): WebpackLoggingCallback {
const { verbose = false, scripts = [], styles = [] } = options;
const extraEntryPoints = [
...normalizeExtraEntryPoints(styles, 'styles'),
...normalizeExtraEntryPoints(scripts, 'scripts'),
];

return (stats, config) => {
if (verbose) {
logger.info(stats.toString(config.stats));
}

webpackStatsLogger(logger, stats.toJson(getWebpackStatsConfig(false)), config);
const rawStats = stats.toJson(getWebpackStatsConfig(false));
const webpackStats = {
...rawStats,
chunks: markAsyncChunksNonInitial(rawStats, extraEntryPoints),
};

webpackStatsLogger(logger, webpackStats, config);
};
}

Expand Down

0 comments on commit 2d0d82b

Please sign in to comment.