Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): provide supported browsers to esb…
Browse files Browse the repository at this point in the history
…uild

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
  • Loading branch information
alan-agius4 authored and clydin committed Aug 18, 2021
1 parent b7199f3 commit a55118a
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
`^(${Object.keys(entryPoints).join('|')})(\.[0-9a-f]{20})?.css$`,
);

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

return {
Expand Down Expand Up @@ -478,3 +480,19 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
plugins: extraPlugins,
};
}

function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[] | undefined {
const transformed: string[] = [];

// https://esbuild.github.io/api/#target
const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);

for (const browser of supportedBrowsers) {
const [browserName, version] = browser.split(' ');
if (esBuildSupportedBrowsers.has(browserName)) {
transformed.push(browserName + version);
}
}

return transformed.length ? transformed : undefined;
}

0 comments on commit a55118a

Please sign in to comment.