Skip to content

Commit 238438e

Browse files
committed
refactor(@angular-devkit/build-angular): remove BundleBudgetPlugin
Remove BundleBudgetPlugin, and instead use the `checkBudgets` method directly in the browser buillder.
1 parent d3a3635 commit 238438e

File tree

4 files changed

+19
-82
lines changed

4 files changed

+19
-82
lines changed

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export function buildWebpackBrowser(
296296

297297
return { success };
298298
} else {
299+
const processResults: ProcessBundleResult[] = [];
299300
const bundleInfoStats: BundleStats[] = [];
300301
outputPaths = ensureOutputPaths(baseOutputPath, i18n);
301302

@@ -445,7 +446,6 @@ export function buildWebpackBrowser(
445446

446447
const processActions: typeof actions = [];
447448
let processRuntimeAction: ProcessBundleOptions | undefined;
448-
const processResults: ProcessBundleResult[] = [];
449449
for (const action of actions) {
450450
// If SRI is enabled always process the runtime bundle
451451
// Lazy route integrity values are stored in the runtime bundle
@@ -598,22 +598,6 @@ export function buildWebpackBrowser(
598598
const asset = webpackStats.assets?.find(a => a.name === chunk.files[0]);
599599
bundleInfoStats.push(generateBundleStats({ ...chunk, size: asset?.size }));
600600
}
601-
602-
// Check for budget errors and display them to the user.
603-
const budgets = options.budgets || [];
604-
const budgetFailures = checkBudgets(budgets, webpackStats, processResults);
605-
for (const { severity, message } of budgetFailures) {
606-
switch (severity) {
607-
case ThresholdSeverity.Warning:
608-
webpackStats.warnings.push(message);
609-
break;
610-
case ThresholdSeverity.Error:
611-
webpackStats.errors.push(message);
612-
break;
613-
default:
614-
assertNever(severity);
615-
}
616-
}
617601
} else {
618602
files = emittedFiles.filter(x => x.name !== 'polyfills-es5');
619603
noModuleFiles = emittedFiles.filter(x => x.name === 'polyfills-es5');
@@ -636,6 +620,24 @@ export function buildWebpackBrowser(
636620
}
637621
}
638622

623+
// Check for budget errors and display them to the user.
624+
const budgets = options.budgets;
625+
if (budgets?.length) {
626+
const budgetFailures = checkBudgets(budgets, webpackStats, processResults);
627+
for (const { severity, message } of budgetFailures) {
628+
switch (severity) {
629+
case ThresholdSeverity.Warning:
630+
webpackStats.warnings.push(message);
631+
break;
632+
case ThresholdSeverity.Error:
633+
webpackStats.errors.push(message);
634+
break;
635+
default:
636+
assertNever(severity);
637+
}
638+
}
639+
}
640+
639641
// Copy assets
640642
if (!options.watch && options.assets?.length) {
641643
spinner.start('Copying assets...');

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import { findAllNodeModules } from '../../utils/find-up';
3939
import { Spinner } from '../../utils/spinner';
4040
import { isWebpackFiveOrHigher, withWebpackFourOrFive } from '../../utils/webpack-version';
4141
import {
42-
BundleBudgetPlugin,
4342
DedupeModuleResolvePlugin,
4443
NamedLazyChunksPlugin,
4544
OptimizeCssWebpackPlugin,
@@ -361,17 +360,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
361360
);
362361
}
363362

364-
if (buildOptions.budgets.length && !differentialLoadingMode) {
365-
// Budgets are computed after differential builds, not via a plugin.
366-
// https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/browser/index.ts
367-
const extraEntryPoints = [
368-
...normalizeExtraEntryPoints(buildOptions.styles || [], 'styles'),
369-
...normalizeExtraEntryPoints(buildOptions.scripts || [], 'scripts'),
370-
];
371-
372-
extraPlugins.push(new BundleBudgetPlugin({ budgets: buildOptions.budgets, extraEntryPoints }));
373-
}
374-
375363
if ((scriptsSourceMap || stylesSourceMap)) {
376364
extraRules.push({
377365
test: /\.m?js$/,

packages/angular_devkit/build_angular/src/webpack/plugins/bundle-budget.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/webpack/plugins/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// Exports the webpack plugins we use internally.
1010
export { AnyComponentStyleBudgetChecker } from './any-component-style-budget-checker';
1111
export { OptimizeCssWebpackPlugin, OptimizeCssWebpackPluginOptions } from './optimize-css-webpack-plugin';
12-
export { BundleBudgetPlugin, BundleBudgetPluginOptions } from './bundle-budget';
1312
export { ScriptsWebpackPlugin, ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';
1413
export { SuppressExtractedTextChunksWebpackPlugin } from './suppress-entry-chunks-webpack-plugin';
1514
export { RemoveHashPlugin, RemoveHashPluginOptions } from './remove-hash-plugin';

0 commit comments

Comments
 (0)