Skip to content

Commit 3e33218

Browse files
committed
fix(@angular-devkit/build-angular): RGBA converted to hex notation in component styles breaks IE11
ESBuild which is used to optimize CSS in components, doesn't support IE. With this change we workaround this limitation by adding `Edge 12` when the user needs `IE 11` support. Closes #21652
1 parent 97ea4c1 commit 3e33218

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/angular_devkit/build_angular/src/browser/specs/styles_spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,5 +700,36 @@ describe('Browser Builder styles', () => {
700700
};
701701
await browserBuild(architect, host, target, overrides);
702702
});
703+
704+
it('should minify colors based on browser support', async () => {
705+
host.writeMultipleFiles({
706+
'src/app/app.component.css': `
707+
div { box-shadow: 0 3px 10px, rgba(0, 0, 0, 0.15); }
708+
`,
709+
});
710+
host.replaceInFile('tsconfig.json', 'es2017', 'es5');
711+
712+
let result = await browserBuild(architect, host, target, { optimization: true, aot: true });
713+
expect(await result.files['main.js']).toContain('#00000026');
714+
715+
await host.restore().toPromise();
716+
await host.initialize().toPromise();
717+
architect = (await createArchitect(host.root())).architect;
718+
719+
// IE 11 doesn't support #rrggbbaa colors
720+
// https://github.com/angular/angular-cli/issues/21594#:~:text=%23rrggbbaa%20hex%20color%20notation
721+
// While this browser is un-supported, this is used as a base case to test that the underlying
722+
// logic to pass the list of supported browsers to the css optimizer works.
723+
host.writeMultipleFiles({
724+
'src/app/app.component.css': `
725+
div { box-shadow: 0 3px 10px, rgba(0, 0, 0, 0.15); }
726+
`,
727+
'.browserslistrc': 'ie 11',
728+
});
729+
host.replaceInFile('tsconfig.json', 'es2017', 'es5');
730+
731+
result = await browserBuild(architect, host, target, { optimization: true, aot: true });
732+
expect(await result.files['main.js']).toContain('rgba(0,0,0,.149)');
733+
});
703734
});
704735
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ function transformSupportedBrowsersToTargets(supportedBrowsers: string[]): strin
489489

490490
for (const browser of supportedBrowsers) {
491491
const [browserName, version] = browser.split(' ');
492-
if (esBuildSupportedBrowsers.has(browserName)) {
492+
493+
if (browserName === 'ie') {
494+
transformed.push('edge12');
495+
} else if (esBuildSupportedBrowsers.has(browserName)) {
493496
transformed.push(browserName + version);
494497
}
495498
}

0 commit comments

Comments
 (0)