@rari/font self-hosts fonts. At build time it copies local font files, or downloads Google Fonts, into your build output, generates the @font-face rules, and adds a size-adjusted fallback so text doesn't shift while the font loads. Nothing is requested from Google at runtime.

Fonts are a separate package, so apps that don't use them don't install the font tooling.

Install

Terminal
bash
$ npm install @rari/font

No configuration is needed: the rari Vite plugin detects @rari/font and registers its font handling.

Google Fonts

Import a family by name from @rari/font/google and call it with a static options object:

src/app/layout.tsx
import type { LayoutProps } from 'rari'
import { Inter } from '@rari/font/google'

const inter = Inter({ subsets: ['latin'], weight: ['400', '700'] })

export default function RootLayout({ children }: LayoutProps) {
  return (
    <html lang="en" className={inter.className}>
      <body>{children}</body>
    </html>
  )
}

Options include weight, style, subsets, display, variable, preload, fallback, adjustFontFallback, and axes (for variable fonts).

Local fonts

Import localFont from @rari/font/local and point src at files inside your project:

src/app/fonts.ts
import localFont from '@rari/font/local'

export const brand = localFont({
  src: [
    { path: './fonts/Brand-Regular.woff2', weight: '400' },
    { path: './fonts/Brand-Bold.woff2', weight: '700' },
  ],
  variable: '--font-brand',
})

Using a font

Each call returns:

  • className: applies the font family.
  • style: an object with fontFamily, fontWeight, and fontStyle (unless it's normal), for inline styles.
  • variable: when you pass variable, a class that defines that CSS custom property, so you can use var(--font-brand) in your own CSS.

The options must be a static object literal, because they're read at build time.

Migrating from rari/font

Fonts used to ship inside rari as rari/font/local and rari/font/google. Those imports have been removed, and a build that still uses them fails with a message pointing here. To migrate:

  1. Install the package: npm install @rari/font.
  2. Replace rari/font/ with @rari/font/ in your imports.

The options and return values haven't changed.