# nuxt-font-preload

> Preload custom fonts in Nuxt

Latest version **0.1.5** (published 2023-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install nuxt-font-preload
pnpm add nuxt-font-preload
yarn add nuxt-font-preload
bun add nuxt-font-preload
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2023-12-09 |
| First published | 2023-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Dananz |
| Maintainers | dananz |

## Links

- npm: https://www.npmjs.com/package/nuxt-font-preload
- Repository: https://github.com/dananz/nuxt-font-preload
- Homepage: https://github.com/dananz/nuxt-font-preload#readme
- Issues: https://github.com/dananz/nuxt-font-preload/issues
- npm.io page: https://npm.io/package/nuxt-font-preload

## Dependencies (1)

- [@nuxt/kit](https://npm.io/package/@nuxt/kit.md) ^3.8.2

## Recent versions

- 0.1.5 (latest) — 2023-12-09
- 0.1.4 — 2023-12-09
- 0.1.3 — 2023-12-09
- 0.1.2 — 2023-12-09

## README

# Nuxt Font Preload

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
[![Nuxt][nuxt-src]][nuxt-href]

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.

- [✨ &nbsp;Release Notes](/CHANGELOG.md)
- [🏀 Online playground](https://stackblitz.com/github/dananz/nuxt-font-preload?file=playground%2Fapp.vue)
  <!-- - [📖 &nbsp;Documentation](https://example.com) -->

## Features

- 💡 &nbsp;Declares custom fonts using `@font-face`
- ✋ &nbsp;Reduces CLS by preloading fonts
- ✨ &nbsp;Easy integration with Nuxt 3

## Quick Setup

1. Add `nuxt-font-preload` dependency to your project

```bash
npm i -D nuxt-font-preload
```

2. Add `nuxt-font-preload` to the `modules` section of `nuxt.config.ts`

```js
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:

1. Clone this repository
2. Install dependencies using `pnpm install`
3. Prepare development server using `pnpm dev:prepare`
4. Build module using `pnpm prepack`
5. Launch playground using `pnpm dev`

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/nuxt-font-preload/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/nuxt-font-preload
[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-font-preload.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/nuxt-font-preload
[license-src]: https://img.shields.io/npm/l/nuxt-font-preload.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/nuxt-font-preload
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
[nuxt-href]: https://nuxt.com

---
_Source: https://npm.io/package/nuxt-font-preload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
