Skip to content

fix(@angular-devkit/build-angular): styles that are not injected do count for initial bundle size #19876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ export function buildWebpackBrowser(
}

// Fix incorrectly set `initial` value on chunks.
const extraEntryPoints = normalizeExtraEntryPoints(options.styles || [], 'styles')
.concat(normalizeExtraEntryPoints(options.scripts || [], 'scripts'));
const extraEntryPoints = [
...normalizeExtraEntryPoints(options.styles || [], 'styles'),
...normalizeExtraEntryPoints(options.scripts || [], 'scripts'),
];

const webpackStats = {
...webpackRawStats,
chunks: markAsyncChunksNonInitial(webpackRawStats, extraEntryPoints),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,15 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
);
}

if (!differentialLoadingMode) {
if (buildOptions.budgets.length && !differentialLoadingMode) {
// Budgets are computed after differential builds, not via a plugin.
// https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/browser/index.ts
extraPlugins.push(new BundleBudgetPlugin({ budgets: buildOptions.budgets }));
const extraEntryPoints = [
...normalizeExtraEntryPoints(buildOptions.styles || [], 'styles'),
...normalizeExtraEntryPoints(buildOptions.scripts || [], 'scripts'),
];

extraPlugins.push(new BundleBudgetPlugin({ budgets: buildOptions.budgets, extraEntryPoints }));
}

if ((scriptsSourceMap || stylesSourceMap)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import { Budget } from '../../browser/schema';
import { ThresholdSeverity, checkBudgets } from '../../utils/bundle-calculator';
import { ProcessBundleResult } from '../../utils/process-bundle';
import { addError, addWarning } from '../../utils/webpack-diagnostics';
import { markAsyncChunksNonInitial } from '../utils/async-chunks';
import { NormalizedEntryPoint } from '../utils/helpers';

export interface BundleBudgetPluginOptions {
budgets: Budget[];
extraEntryPoints: NormalizedEntryPoint[];
}

export class BundleBudgetPlugin {
Expand All @@ -30,7 +33,10 @@ export class BundleBudgetPlugin {
// builds are disabled.
const processResults: ProcessBundleResult[] = [];

// Fix incorrectly set `initial` value on chunks.
const stats = compilation.getStats().toJson();
stats.chunks = markAsyncChunksNonInitial(stats, this.options.extraEntryPoints);

for (const { severity, message } of checkBudgets(budgets, stats, processResults)) {
switch (severity) {
case ThresholdSeverity.Warning:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as webpack from 'webpack';
import { NormalizedEntryPoint } from '../configs';
import { NormalizedEntryPoint } from './helpers';

/**
* Webpack stats may incorrectly mark extra entry points `initial` chunks, when
Expand Down