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

vite-plugin-svg2font

v1.0.0

Published

vite-plugin svg2font

Downloads

11

Readme

vite-plugin-svg2font

A vite plugin to convert svg icons to iconfont。
Convert multiple SVG icons into a single font file and a CSS file, and CSS will be automatically imported into 'index. html'. Then use the svg file name as the class name for the icon (eg: react.svg: <i class="icon-react"></i>)

Why

When working on a project, designers often provide us with icons in the form of SVG files. Using SVG as icons is not as convenient as using font icons. In the past, I would create a project on iconfont, upload the SVG files to my project, and then use the generated font icons via an online link. However, there were some issues with this approach. For example, when multiple developers were using the same iconfont project, the URL would change frequently, resulting in the need to changes to files referencing this URL many times. Additionally, the iconfont website now has an approval mechanism, which makes it less convenient to use.

To solve these problems, I developed this plugin. This plugin converts all SVG files in a specified directory into a single font file and a CSS file. The CSS file is automatically included in index.html, so developers can simply use <i class="icon-add"></i> to display an icon (where "icon-add" corresponds to the "add.svg" SVG file). Whenever there are changes in the SVG directory, the plugin will automatically compile and process all SVG files.

Get started

  1. Install vite and this plugin with your favorite package manager, here use npm as example:

    npm install vite vite-plugin-svg2font -D
  2. Create a vite.config.ts file in your project root to config vite to actually use this plugin:

    import { defineConfig } from "vite";
    import svg2font from "vite-plugin-svg2font";
    
    export default defineConfig({
      plugins: [
        svg2font({
          svgPath: "src/assets/svg-icons",
          fileName: "iconfont",
          targetPath: "assets",
        }),
      ],
    });
  3. Tips:

  • Please ensure that only '' tags are included in the svg file, and there is no need to include '', otherwise compilation errors may occur
  • Please ensure that all SVG icons have the same size as,eg: <svg width="32" height="32">....</ svg>

options

interface Svg2FontOption {
  /**
   * SVG icon directory path, the plugin will convert all SVG files in this directory into a single font file, relative to the project root directory
   * SVG file name is use to icon className
   */
  svgPath: string;
  /**
   * Specify the name of the generated CSS file and font file. Please do not include the file extensions
   */
  fileName: string;
  /**
   * The location for storing CSS files and font files during the build.
   * relative to the target path (build.outDir). By default, it uses build.assetsDir."
   */
  targetPath?: string;
  /**
   * class prefix. default "icon"
   * eg. icon-react icon-vue
   */
  classPrefix?: string;
}

Examples

See the examples folder.

License

React is MIT licensed.