fix(@angular-devkit/build-angular): properly handle comment removal during font inlining

Closes #19350
This commit is contained in:
Alan Agius 2020-11-12 09:55:54 +01:00 committed by Charles
parent 313c3f2340
commit 1237ddacea
2 changed files with 23 additions and 2 deletions

View File

@ -159,10 +159,10 @@ export class InlineFontsProcessor {
if (this.options.minifyInlinedCSS) {
cssContent = cssContent
// Comments.
.replace(/\/\*([\s\S]*?)\*\//g, '')
// New lines.
.replace(/\n/g, '')
// Comments and new lines.
.replace(/\/\*\s.+\s\*\//g, '')
// Safe spaces.
.replace(/\s?[\{\:\;]\s+/g, s => s.trim());
}

View File

@ -39,6 +39,27 @@ describe('InlineFontsProcessor', () => {
expect(html).toContain(`font-family: 'Material Icons'`);
});
it('should inline multiple fonts from a single request with minification enabled', async () => {
const inlineFontsProcessor = new InlineFontsProcessor({
minifyInlinedCSS: true,
WOFFSupportNeeded: false,
});
const html = await inlineFontsProcessor.process(`
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500%7CGoogle+Sans:400,500%7CRoboto+Mono:400,500%7CMaterial+Icons&display=swap" rel="stylesheet">
<link href="theme.css" rel="stylesheet">
</head>
<body></body>
</html>`);
expect(html).toContain(`'Google Sans'`);
expect(html).toContain(`'Roboto'`);
expect(html).toContain(`'Roboto Mono'`);
expect(html).toContain(`'Material Icons'`);
});
it('works with http protocol', async () => {
const inlineFontsProcessor = new InlineFontsProcessor({
WOFFSupportNeeded: false,