Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): properly handle comment removal d…
Browse files Browse the repository at this point in the history
…uring font inlining

Closes #19350

(cherry picked from commit 1237dda)
  • Loading branch information
alan-agius4 authored and clydin committed Nov 12, 2020
1 parent 3971ad0 commit 63ca8b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 63ca8b8

Please sign in to comment.