Skip to content

Commit a0a2c7a

Browse files
committedJul 10, 2023
perf(@angular-devkit/build-angular): only load browserslist in babel preset if needed
The `browserslist` package is only needed in the custom Babel application preset if the `supportedBrowsers` option is specified. This option is not used within the esbuild- based browser application builder. The `browserslist` is now lazily imported only when needed and avoids the overhead of loading browser support data when not needed by the build.
1 parent 974748c commit a0a2c7a

File tree

1 file changed

+16
-12
lines changed
  • packages/angular_devkit/build_angular/src/tools/babel/presets

1 file changed

+16
-12
lines changed
 

‎packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import type {
1313
makeEs2015TranslatePlugin,
1414
makeLocalePlugin,
1515
} from '@angular/localize/tools';
16-
import { strict as assert } from 'assert';
17-
import browserslist from 'browserslist';
18-
import * as fs from 'fs';
19-
import * as path from 'path';
16+
import assert from 'node:assert';
17+
import fs from 'node:fs';
18+
import path from 'node:path';
2019
import { loadEsmModule } from '../../../utils/load-esm';
2120

2221
/**
@@ -31,14 +30,7 @@ let needsLinking: typeof import('@angular/compiler-cli/linker').needsLinking | u
3130
* See: https://github.com/angular/angular-cli/issues/24355#issuecomment-1333477033
3231
* See: https://github.com/WebKit/WebKit/commit/e8788a34b3d5f5b4edd7ff6450b80936bff396f2
3332
*/
34-
const safariClassFieldScopeBugBrowsers = new Set(
35-
browserslist([
36-
// Safari <15 is technically not supported via https://angular.io/guide/browser-support,
37-
// but we apply the workaround if forcibly selected.
38-
'Safari <=15',
39-
'iOS <=15',
40-
]),
41-
);
33+
let safariClassFieldScopeBugBrowsers: ReadonlySet<string>;
4234

4335
export type DiagnosticReporter = (type: 'error' | 'warning' | 'info', message: string) => void;
4436

@@ -198,6 +190,18 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
198190
if (options.supportedBrowsers) {
199191
const includePlugins: string[] = [];
200192

193+
if (safariClassFieldScopeBugBrowsers === undefined) {
194+
const browserslist = require('browserslist');
195+
safariClassFieldScopeBugBrowsers = new Set(
196+
browserslist([
197+
// Safari <15 is technically not supported via https://angular.io/guide/browser-support,
198+
// but we apply the workaround if forcibly selected.
199+
'Safari <=15',
200+
'iOS <=15',
201+
]),
202+
);
203+
}
204+
201205
// If a Safari browser affected by the class field scope bug is selected, we
202206
// downlevel class properties by ensuring the class properties Babel plugin
203207
// is always included- regardless of the preset-env targets.

0 commit comments

Comments
 (0)
Please sign in to comment.