Integrations

@nuxt/fonts

Last updated by Harlan Wilton in feat!: nuxt/fonts integration (#432) * feat: add provider dependency onboarding with Nuxt install/upgrade hooks - Move provider deps (satori, resvg, takumi, playwright, sharp, css-inline) to optional peerDependencies - Add onInstall hook with interactive provider/binding selection - Add onUpgrade hook for deprecated config detection - Validate renderer dependencies in setup, block if missing - Skip onboarding with NUXT_OG_IMAGE_SKIP_ONBOARDING=1 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: add cloudflare-takumi fixture for edge runtime e2e testing Tests takumi renderer with WASM bindings on cloudflare-pages preset Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: cloudflare workers compatibility and takumi WASM bindings - Fix takumi WASM import path and init API for @takumi-rs/wasm - Use virtual modules for edge runtime package stubs to avoid CJS resolution issues - Add canvas mock for linkedom on edge runtimes - Add wrangler.toml for cloudflare-takumi test fixture - Simplify cloudflare-takumi fixture config (auto-detects cloudflare-module preset) - Add .wrangler to .gitignore Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: move cloudflare-takumi e2e test to e2e-not-nuxt - Add comprehensive cloudflare-takumi test with prerendered and wrangler runtime tests - Move from test/e2e to test/e2e-not-nuxt (doesn't use @nuxt/test-utils) - Add snapshots for prerendered and runtime-generated images Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: use solid color instead of gradient in cloudflare-takumi fixture Gradients don't work with takumi renderer, use solid bg-purple-600. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * test: add cloudflare-satori e2e test fixture Tests satori renderer with WASM bindings on cloudflare workers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * doc: sync * chore: sync * chore: sync * feat: nuxt/fonts integration WIP * chore: sync * chore: sync * fix: offload fonts to public dir for edge runtimes Fixes #155 * chore: progress commit * chore: progress commit * chore: progress commit * chore: progress commit * chore: progress commit * chore: progress commit * chore: progress commit * chore: typecheck * chore: typecheck * fix: wrong fonts bindings for runtime * chore: missing fixtures * fix: respect base URL * chore: sync * chore: sync * chore: sync --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>.

Nuxt OG Image uses @nuxt/fonts for font management. This is required for custom fonts.

Setup

  1. Install @nuxt/fonts:
npx nuxi module add @nuxt/fonts
  1. Configure your fonts in nuxt.config.ts with global: true:
nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@nuxt/fonts', 'nuxt-og-image'],

  fonts: {
    families: [
      { name: 'Inter', weights: [400, 700], global: true },
    ],
  },
})
The global: true option is required for fonts to be available in OG Image rendering. Without it, fonts won't be loaded.
  1. Use the font in your OG Image template:
components/OgImage/MyTemplate.vue
<template>
  <div style="font-family: 'Inter'">
    <h1>{{ title }}</h1>
  </div>
</template>

How It Works

  1. Build time: Nuxt OG Image resolves your configured font families using the same providers as @nuxt/fonts
  2. Runtime: Fonts are fetched from provider URLs (e.g., Google Fonts) and cached
  3. No @nuxt/fonts: If not installed, no fonts are available for rendering

Provider Configuration

Use any provider supported by @nuxt/fonts:

nuxt.config.ts
export default defineNuxtConfig({
  fonts: {
    families: [
      // Google Fonts (default provider)
      { name: 'Roboto', weights: [400, 700], global: true },

      // Explicit provider
      { name: 'Inter', provider: 'bunny', weights: [400, 700], global: true },

      // Local fonts (must be woff2 format)
      {
        name: 'MyFont',
        src: '/fonts/MyFont.woff2',
        weight: 400,
        global: true,
      },
    ],
  },
})

Font Format

Different renderers support different font formats:

FormatSatoriTakumiChromium
woff2
woff
ttf
otf
When using Google Fonts or other providers, @nuxt/fonts automatically fetches the correct format. Format compatibility only matters for local fonts.

Troubleshooting

Font not rendering

  1. Ensure the font has global: true set
  2. Ensure the font is listed in fonts.families
  3. For local fonts, ensure format matches your renderer (see table above)

China/Blocked regions

For regions where Google Fonts is blocked, use local fonts or an alternative provider:

export default defineNuxtConfig({
  fonts: {
    providers: {
      google: false,
    },
    families: [
      {
        name: 'Inter',
        src: '/fonts/Inter-Regular.woff2',
        weight: 400,
        global: true,
      },
    ],
  }
})
Did this page help you?