npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hypernym/nuxt-font

v2.0.2

Published

Auto-optimized font loader for Nuxt.

Downloads

396

Readme

Nuxt Font Module

Auto-optimized font loader for Nuxt.

Features

  • Includes automatic optimization
  • Provides a composable font strategy
  • Follows modern methods and practices
  • TypeScript friendly
  • Super easy to use
  • No dependencies
  • Ultra lightweight

Quick Start

  1. Install @hypernym/nuxt-font to your project
npm i -D @hypernym/nuxt-font
  1. Enable the module in the main config file
// nuxt.config.ts

{
  modules: ['@hypernym/nuxt-font']
}

That's it!

Optimization

The module automatically optimizes all your font sources and improves page loading speed so you don't have to worry about it at all.

It is designed with performance, flexibility and privacy in mind.

Module

Fonts are loaded via custom useFont composable from the same domain as your deployment.

Using this strategy, you can easily load fonts on different components, pages or layouts.

Since it only supports local fonts, the module final size is super tiny.

Local Fonts

The term local fonts refers to fonts that will be hosted with your site as well as other assets, so you have full control over them without involvement of third-party services. This is essential for speed and privacy.

Also, most fonts used on the web today are released under the OFL-1.1 license or some similar open-source code, which includes their download and free use.

For external font loading, check out nuxt-font-loader.

Usage

Place the previously downloaded fonts in the public/ directory.

After that, use the composable exactly where you need it.

<!-- layout.vue | page.vue | component.vue -->

<template>
  <h1 class="font-aspekta">Nuxt Font Module</h1>
</template>

<script setup lang="ts">
  useFont([
    {
      src: '/fonts/AspektaVF.woff2',
      family: 'Aspekta Variable',
      weight: '100 900',
      class: 'font-aspekta',
    },
  ])
</script>

Options

Nuxt Font Module is optimized and supports Nuxt 3 with TypeScript. It also improves the development experience with detailed descriptions, examples and code auto-completion.

// nuxt.config.ts

{
  modules: ['@hypernym/nuxt-font'],

  font: {
    // Module options
  }
}

useFont

Loads fonts from the same domain as your deployment.

The function accepts an array of objects that specifies local font sources.

Each object is treated as a separate block of rules.

Also, the font composable is available globally after module activation, so there is no need for manual import.

// Explicit import (optional)

import { useFont } from '#font'

src

  • Type: string
  • Required: true

Specifies path to the font file.

Fonts must be placed within a public/ directory.

useFont([
  {
    src: '/fonts/AspektaVF.woff2',
  },
])

family

  • Type: string
  • Required: true

Specifies the font family name.

useFont([
  {
    family: 'Aspekta Variable',
  },
])

preload

  • Type: boolean
  • Default: true

Specifies the preload links.

useFont([
  {
    preload: true,
  },
])

fallback

  • Type: string[]
  • Default: ['sans-serif']

Specifies the font family fallback.

useFont([
  {
    fallback: ['sans-serif'],
  },
])

Example above will generate:

.font-aspekta {
  font-family: 'Aspekta Variable', sans-serif;
}

weight

  • Type: string
  • Default: '400'

Specifies the font weight.

useFont([
  {
    // variable weight range
    weight: '100 900',
  },
])

style

  • Type: string
  • Default: 'normal'

Specifies the font style.

useFont([
  {
    style: 'italic',
  },
])

display

  • Type: string
  • Default: 'optional'

Specifies how a font face is displayed.

useFont([
  {
    display: 'swap',
  },
])

class

  • Type: string
  • Default: undefined

Specifies the global css class for the current source.

useFont([
  {
    class: 'font-aspekta',
  },
])

Example above will generate global css class:

.font-aspekta {
  font-family: 'Aspekta Variable', sans-serif;
}

So it can be used in templates:

<h1 class="font-aspekta">Font Loader</h1>

variable

  • Type: string
  • Default: undefined

Specifies the global css variable for the current source.

useFont([
  {
    variable: 'font-aspekta',
  },
])

Example above will generate global css variable:

:root {
  --font-aspekta: 'Aspekta Variable', sans-serif;
}

So it can be used in templates:

h1 {
  font-family: var(--font-aspekta);
}

unicode

  • Type: string[]
  • Default: undefined

Specifies the range of characters to be used from the font.

useFont([
  {
    preload: false,
    display: 'swap',
    unicode: ['U+26'],
  },
])

Example above will generate:

@font-face {
  font-display: swap;
  unicode-range: U+26;
}

autoImport

  • Type: boolean
  • Default: true

Specifies the built-in auto-import feature.

If enabled, font composables are available globally so there is no need for manual import.

// nuxt.config.ts

{
  font: {
    autoImport: true
  }
}

Community

Feel free to use the official discussions for any additional questions.

License

Developed in 🇭🇷 Croatia

Released under the MIT license.

© Hypernym Studio