Skip to content

Commit a55118a

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular-devkit/build-angular): provide supported browsers to esbuild
With this change we provide the list of supported browsers to Esbuild during CSS optimizations, so it can perform optimizations based on the browser support needed. Closes #21594
1 parent b7199f3 commit a55118a

File tree

1 file changed

+18
-0
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
300300
`^(${Object.keys(entryPoints).join('|')})(\.[0-9a-f]{20})?.css$`,
301301
);
302302

303+
const target = transformSupportedBrowsersToTargets(supportedBrowsers);
303304
extraMinimizers.push(
304305
// Component styles use esbuild which is faster and generates smaller files on average.
305306
// esbuild does not yet support style sourcemaps but component style sourcemaps are not
@@ -315,6 +316,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
315316
loader: 'css',
316317
minify: true,
317318
sourcefile,
319+
target,
318320
});
319321

320322
return {
@@ -478,3 +480,19 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
478480
plugins: extraPlugins,
479481
};
480482
}
483+
484+
function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[] | undefined {
485+
const transformed: string[] = [];
486+
487+
// https://esbuild.github.io/api/#target
488+
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);
489+
490+
for (const browser of supportedBrowsers) {
491+
const [browserName, version] = browser.split(' ');
492+
if (esBuildSupportedBrowsers.has(browserName)) {
493+
transformed.push(browserName + version);
494+
}
495+
}
496+
497+
return transformed.length ? transformed : undefined;
498+
}

0 commit comments

Comments
 (0)