nuxt-font-preload
v0.1.5
Published
Preload custom fonts in Nuxt
Downloads
287
Readme
Nuxt Font Preload
Minimize Content Layout Shifts (CLS) by preloading fonts. A developer-focused tool for font preloading, nuxt-font-preload
will automatically generates
<link rel="preload">
tags and @font-face
declarations for your custom fonts.
[!NOTE] This module is intended for use with self-hosted fonts, and does not support Google Fonts or other external font providers.
Features
- 💡 Declares custom fonts using
@font-face
- ✋ Reduces CLS by preloading fonts
- ✨ Easy integration with Nuxt 3
Quick Setup
- Add
nuxt-font-preload
dependency to your project
npm i -D nuxt-font-preload
- Add
nuxt-font-preload
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: ["nuxt-font-preload"],
fontPreload: {
fonts: [
{
fontFamily: "Montserrat",
weights: [
{
weight: 400,
sources: [
{
url: "fonts/Montserrat-Regular.woff2",
format: "woff2",
preload: true,
},
],
},
],
// Applies to all weights
defaultOptions: { fontDisplay: "swap" },
},
],
},
});
That's it! Your Nuxt app will now preload fonts efficiently ✨
Contributing
You can contribute to this module and test it locally by following these steps:
- Clone this repository
- Install dependencies using
pnpm install
- Prepare development server using
pnpm dev:prepare
- Build module using
pnpm prepack
- Launch playground using
pnpm dev