load fonts in NextJS
See original GitHub issueI cannot manage to load web fonts in NextJS following what it’s said here: https://www.dripsy.xyz/fonts#web-optimizations
Normally you need to load them within styles (tailwind), right?
font-family: 'IBM Plex Sans';
font-style: normal;
font-weight: 100 900;
font-display: optional;
src: url(/fonts/ibm-plex-sans-var.woff2) format('woff2');
}
But with Dripsy, DripsyProvider is in charge of it?
This my _document.tsx
<link
rel="preload"
href="/fonts/Inter/Inter-Regular.ttf"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="/fonts/Inter/Inter-bold.ttf"
as="font"
crossOrigin=""
/>
theme.tsx
export const fontName = 'Inter'
const webFont = (font: string) =>
Platform.select({
web: `${font}, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, Inter-serif`,
default: font,
})
const theme = makeTheme({
colors: darkColors,
customFonts: {
[fontName]: {
bold: webFont(fontName),
default: webFont(fontName),
normal: webFont(fontName)
},
},
fonts: {
root: fontName,
},
text: {
default: {
fontSize: 26,
},
body: {},
bold: {
fontWeight: 'bold',
},
},
})
`` `
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Basic Features: Font Optimization - Next.js
Import @next/font/local and specify the src of your local font file. We recommend using variable fonts for the best performance and flexibility. ......
Read more >How to Add Font in Next.js (12.0.1 Updated) | Nextjs - Medium
Download font locally and add it to Next.js · Add CSS to a specific website page. · Use Font in CSS To apply...
Read more >How to Add Web Fonts to a Next.js Website - MakeUseOf
To add self-hosted fonts in Next.js, you need to use the @font-face CSS rule. This rule allows you to add custom fonts to...
Read more >How to load custom fonts in NextJS!? - Reddit
1 add custom fonts to /public/fonts (at least how I did it) · 2 create a global.css file, put in the root directory...
Read more >How to Add Custom Local Fonts in Next.js ? - GeeksforGeeks
How to Add Custom Local Fonts in Next.js ? · Some of the key features of Next.js are: · Step 1: Create a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just put it in
public
and load it using CSS fontface in_document.tsx
, along woth<link>
tags.I added an example to Solito with custom fonts using Dripsy, Next.js and Expo font:
You can see it here.