Skip to content

Commit 3376274

Browse files
Merge pull request #81 from Chiman2937/fix/next-font-local-nextjs-vite
fix: resolve next/font/local loading issues
2 parents 51e6cb0 + 11b21f5 commit 3376274

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/plugins/next-font/local/get-font-face-declarations.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ export async function getFontFaceDeclarations(options: LoaderOptions) {
7272
if ("fontReferenceId" in localFontSrc) {
7373
return dedent`@font-face {
7474
font-family: ${id};
75-
src: url(${localFontSrc.fontReferenceId ? getPlaceholderFontUrl(localFontSrc.fontReferenceId) : `/@fs${localFontSrc.fontPath}`})
75+
src: url(${localFontSrc.fontReferenceId ? getPlaceholderFontUrl(localFontSrc.fontReferenceId) : `/@fs/${localFontSrc.fontPath}`});
76+
${weight ? `font-weight: ${weight};` : ""}
77+
${style ? `font-style: ${style};` : ""}
7678
${fontDeclarations}
7779
}`;
7880
}
@@ -86,7 +88,7 @@ export async function getFontFaceDeclarations(options: LoaderOptions) {
8688
.map((font) => {
8789
return dedent`@font-face {
8890
font-family: ${id};
89-
src: url(${font.path.fontReferenceId ? getPlaceholderFontUrl(font.path.fontReferenceId) : `/@fs${font.path.fontPath}`});
91+
src: url(${font.path.fontReferenceId ? getPlaceholderFontUrl(font.path.fontReferenceId) : `/@fs/${font.path.fontPath}`});
9092
${font.weight ? `font-weight: ${font.weight};` : ""}
9193
${font.style ? `font-style: ${font.style};` : ""}
9294
${fontDeclarations}

src/plugins/next-font/utils/get-css-meta.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export function getCSSMeta(options: Options) {
1515
.${className} {
1616
font-family: ${options.fontFamily};
1717
${isNextCSSPropertyValid(options.styles) ? `font-style: ${options.styles[0]};` : ""}
18-
${isNextCSSPropertyValid(options.weights) ? `font-weight: ${options.weights[0]};` : ""}
18+
${
19+
isNextCSSPropertyValid(options.weights) &&
20+
!options.weights[0]?.includes(" ")
21+
? `font-weight: ${options.weights[0]};`
22+
: ""
23+
}
1924
}
2025
2126
${
@@ -39,7 +44,9 @@ export function getCSSMeta(options: Options) {
3944
function getClassName({ styles, weights, fontFamily }: Options) {
4045
const font = fontFamily.replaceAll(" ", "-").toLowerCase();
4146
const style = isNextCSSPropertyValid(styles) ? styles[0] : null;
42-
const weight = isNextCSSPropertyValid(weights) ? weights[0] : null;
47+
const weight = isNextCSSPropertyValid(weights)
48+
? weights[0]?.replaceAll(" ", "-")
49+
: null;
4350

4451
return `${font}${style ? `-${style}` : ""}${weight ? `-${weight}` : ""}`;
4552
}

0 commit comments

Comments
 (0)