Skip to content

Commit 7114a0e

Browse files
committed
feat: allow skipping generation of @font-face override declarations
1 parent 01288ea commit 7114a0e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const options = {
5454
resolvePath: (id) => 'file:///path/to/public/dir' + id,
5555
// overrideName: (originalName) => `${name} override`
5656
// sourcemap: false
57+
// skipFontFaceGeneration: (fontFamily) => fontFamily === 'Roboto'
5758
}
5859

5960
// Vite

src/transform.ts

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ interface FontaineTransformOptions {
1717
css?: { value?: string }
1818
fallbacks: string[]
1919
resolvePath?: (path: string) => string | URL
20+
skipFontFaceGeneration?: (name: string) => boolean
2021
/** this should produce an unquoted font family name */
2122
fallbackName?: (name: string) => string
2223
/** @deprecated use fallbackName */
@@ -34,6 +35,9 @@ export const FontaineTransform = createUnplugin(
3435
const fallbackName =
3536
options.fallbackName || options.overrideName || generateFallbackName
3637

38+
const skipFontFaceGeneration =
39+
options.skipFontFaceGeneration || (() => false)
40+
3741
function readMetricsFromId(path: string, importer: string) {
3842
const resolvedPath =
3943
isAbsolute(importer) && path.startsWith('.')
@@ -62,6 +66,7 @@ export const FontaineTransform = createUnplugin(
6266
for (const { family, source } of parseFontFace(matchContent)) {
6367
if (!family) continue
6468
if (!supportedExtensions.some(e => source?.endsWith(e))) continue
69+
if (skipFontFaceGeneration(family)) continue
6570

6671
const metrics =
6772
(await getMetricsForFamily(family)) ||

0 commit comments

Comments
 (0)