From 63ca8b8d60c7dc39785573456b3f0f7eda9ec3cc Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 12 Nov 2020 09:55:54 +0100 Subject: [PATCH] fix(@angular-devkit/build-angular): properly handle comment removal during font inlining Closes #19350 (cherry picked from commit 1237ddaceac7c111d730f4005f96d04fce416836) --- .../src/utils/index-file/inline-fonts.ts | 4 ++-- .../src/utils/index-file/inline-fonts_spec.ts | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts b/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts index aebffd76019a..3d7a3cc245b5 100644 --- a/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts +++ b/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts.ts @@ -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()); } diff --git a/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts b/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts index dbf04237ed35..10c91fc6bd62 100644 --- a/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts +++ b/packages/angular_devkit/build_angular/src/utils/index-file/inline-fonts_spec.ts @@ -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(` + + + + + + + `); + + 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,