MaikoTan/unplugin-fantasticon

Generate icon fonts using fantasticon in various bundler :rocket: :tada:

★ 0Forks 0TypeScriptGitHub ↗Compare

README

unplugin-fantasticon

NPM version

A unplugin plugin to generate iconfonts from SVGs using fantasticon.

Install

npm i -D unplugin-fantasticon
yarn add -D unplugin-fantasticon
pnpm add -D unplugin-fantasticon
Vite
// vite.config.ts
import Fantasticon from 'unplugin-fantasticon/vite'

export default defineConfig({
  plugins: [
    Fantasticon({ /* options */ }),
  ],
})

Example: playground/


Rollup
// rollup.config.js
import Fantasticon from 'unplugin-fantasticon/rollup'

export default {
  plugins: [
    Fantasticon({ /* options */ }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-fantasticon/webpack')({ /* options */ })
  ]
}


Nuxt
// nuxt.config.js
export default defineNuxtConfig({
  modules: [
    ['unplugin-fantasticon/nuxt', { /* options */ }],
  ],
})

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-fantasticon/webpack')({ /* options */ }),
    ],
  },
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'
import Fantasticon from 'unplugin-fantasticon/esbuild'

build({
  plugins: [Fantasticon()],
})


Configuration

This plugin uses the same options as fantasticon.

There are some additional options that can be used to configure the plugin:

generateFonts

  • Type: (userOptions: RunnerOptions, mustWrite?: boolean) => Promise<RunnerResults>
  • Default: generateFonts from @twbs/fantasticon

This option allows you to provide a custom function to generate the icon fonts. The function should return a promise that resolves to the results of the font generation.

injectHtml

  • Type: boolean
  • Default: true

If set to true, the plugin will inject a <link> tag into the HTML files to load the generated CSS file. This is useful for development, but you may want to disable it in production.

Related Projects

  • @twbs/fantasticon: The underlying library used to generate the icon fonts. It is a fork of the original fantasticon library with some improvements and bug fixes.
  • @varlet/unplugin-icon-builder: A similar unplugin that generates icon fonts from SVGs, but uses @varlet/icon-builder instead of fantasticon. It is designed to work with the Varlet UI library, but can be used independently as well.
  • unplugin-icons: A unplugin that provides a collection of popular icon sets as Vue components, React components, and SVGs. It supports various icon sets like FontAwesome, Material Icons, and more.

This plugin is inspired by vite-plugin-fantasticon, which is a Vite plugin that does the same thing.

License

This project is licensed under MIT.

Contributors

MaikoTan

Issues