@coremyslo/nuxt-icon-font
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@coremyslo/nuxt-icon-font

npm version npm downloads License Nuxt

Nuxt icon font generator


Note: This is Nuxt 3 compatible module only.


Features

  • 🕵️‍♂️ Watches specified folder (and sub-folders) with SVG icons and generates fonts on change
  • 💅 Optimizes SVG files via SVGO
  • 🤯 Manual or browserslist based auto-detection of font formats to generate
  • 🏗️ Generates and injects custom properties (variables) with icon codes into pages, where SVG file name is used as a variable name
  • ❤️ Detects and generates the most popular font format as base64 to reduce page jump effect

Usage

<template>
  <p>I'm a text with icon!</p>
</template>
<style scoped lang="scss">
  p {
    &:before {
      content: var(--icon-font-house);
      font-family: "icon-font";
    }
  }
</style>

Setup

  1. Add @coremyslo/nuxt-icon-font dependency to your project
# Using pnpm
pnpm add -D @coremyslo/nuxt-icon-font

# Using yarn
yarn add --dev @coremyslo/nuxt-icon-font

# Using npm
npm install --save-dev @coremyslo/nuxt-icon-font
  1. Add my-module to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    "@coremyslo/nuxt-icon-font"
  ]
})
  1. [Optional] Configure for your needs in nuxt.config.ts. Below is the default configuration.
export default defineNuxtConfig({
  // ...
  iconFont: {
    // Font name to be used in "font-family" and custom properties generated prefix "--icon-font-svgiconfilename"
    name: "icon-font",
    // folder with icons to watch
    sourceDirPath: "assets/icon-font",
    // target folder for generated fonts in "public" folder
    targetDirPath: "icon-font",
    // font formats to generate, fallback to ["woff2"] in case browserslist is not used, example for manual configuration: ["svg", "ttf", "woff", "woff2", "eot"] in any order
    formats: getFontFormatsList(browserslist()),
    // Support of generating the most popular font as base64
    base64: false,
    // unicode symbol for first icon in iconfont (makes sense to change only if you're not going to use custom properties)
    unicode: "0xE900",
    // generated custom properties (variables) format. Other options are: "snake", "pascal", "camel", "header", "constant"
    case: "kebab"
  }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @coremyslo/nuxt-icon-font

Weekly Downloads

147

Version

1.0.1

License

MIT

Unpacked Size

11.8 kB

Total Files

8

Last publish

Collaborators

  • coremyslo