question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

load fonts in NextJS

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nandorojocommented, Apr 18, 2022

I just put it in public and load it using CSS fontface in _document.tsx, along woth <link> tags.

0reactions
nandorojocommented, Sep 13, 2022

I added an example to Solito with custom fonts using Dripsy, Next.js and Expo font:

npx create-solito-app@latest -t with-custom-font

You can see it here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found