From 33028d88e888409c1921b40ea69a8c9767db6c07 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sun, 28 Jul 2024 10:55:45 -0700 Subject: [PATCH] fix(optimize-css): do not remove custom `@font` rules Fixes #65 --- src/plugins/create-optimized-css.ts | 5 +++++ .../__snapshots__/create-optimized-css.test.ts.snap | 12 +++++++++++- tests/create-optimized-css.test.ts | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/plugins/create-optimized-css.ts b/src/plugins/create-optimized-css.ts index 7e2ccf4..08e92c9 100644 --- a/src/plugins/create-optimized-css.ts +++ b/src/plugins/create-optimized-css.ts @@ -104,6 +104,11 @@ export function createOptimizedCss(options: CreateOptimizedCssOptions) { } }); + // Do not proceed if font is not IBM Plex. + if (!attributes["font-family"].startsWith("IBM Plex")) { + return; + } + const is_mono = attributes["font-style"] === "normal" && attributes["font-family"] === "IBM Plex Mono" && diff --git a/tests/__snapshots__/create-optimized-css.test.ts.snap b/tests/__snapshots__/create-optimized-css.test.ts.snap index 19bec55..a7d055f 100644 --- a/tests/__snapshots__/create-optimized-css.test.ts.snap +++ b/tests/__snapshots__/create-optimized-css.test.ts.snap @@ -9,8 +9,13 @@ exports[`create-optimized-css removes unused selectors 1`] = ` " `; -exports[`create-optimized-css removes unused @font rules 1`] = ` +exports[`create-optimized-css removes unused IBM @font rules 1`] = ` " + @font-face { + font-family: 'CustomFont'; + src: url('path/to/custom-font.ttf'); + } + @font-face { font-display: auto; font-family: IBM Plex Mono; @@ -36,6 +41,11 @@ exports[`create-optimized-css removes unused @font rules 1`] = ` exports[`create-optimized-css preserves all IBM fonts 1`] = ` " + @font-face { + font-family: 'CustomFont'; + src: url('path/to/custom-font.ttf'); + } + @font-face { font-display: auto; font-family: IBM Plex Mono; diff --git a/tests/create-optimized-css.test.ts b/tests/create-optimized-css.test.ts index ec3e414..c1e53e1 100644 --- a/tests/create-optimized-css.test.ts +++ b/tests/create-optimized-css.test.ts @@ -17,6 +17,11 @@ describe("create-optimized-css", () => { }); const font_rules = ` + @font-face { + font-family: 'CustomFont'; + src: url('path/to/custom-font.ttf'); + } + @font-face { font-display: auto; font-family: IBM Plex Mono;