Skip to content

Commit 63ca8b8

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular-devkit/build-angular): properly handle comment removal during font inlining
Closes #19350 (cherry picked from commit 1237dda)
1 parent 3971ad0 commit 63ca8b8

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export class InlineFontsProcessor {
161161

162162
if (this.options.minifyInlinedCSS) {
163163
cssContent = cssContent
164+
// Comments.
165+
.replace(/\/\*([\s\S]*?)\*\//g, '')
164166
// New lines.
165167
.replace(/\n/g, '')
166-
// Comments and new lines.
167-
.replace(/\/\*\s.+\s\*\//g, '')
168168
// Safe spaces.
169169
.replace(/\s?[\{\:\;]\s+/g, s => s.trim());
170170
}

packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ describe('InlineFontsProcessor', () => {
3939
expect(html).toContain(`font-family: 'Material Icons'`);
4040
});
4141

42+
it('should inline multiple fonts from a single request with minification enabled', async () => {
43+
const inlineFontsProcessor = new InlineFontsProcessor({
44+
minifyInlinedCSS: true,
45+
WOFFSupportNeeded: false,
46+
});
47+
48+
const html = await inlineFontsProcessor.process(`
49+
<html>
50+
<head>
51+
<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">
52+
<link href="theme.css" rel="stylesheet">
53+
</head>
54+
<body></body>
55+
</html>`);
56+
57+
expect(html).toContain(`'Google Sans'`);
58+
expect(html).toContain(`'Roboto'`);
59+
expect(html).toContain(`'Roboto Mono'`);
60+
expect(html).toContain(`'Material Icons'`);
61+
});
62+
4263
it('works with http protocol', async () => {
4364
const inlineFontsProcessor = new InlineFontsProcessor({
4465
WOFFSupportNeeded: false,

0 commit comments

Comments
 (0)