One-Click Icon Font Generation: icon-font-generator Usage Guide

默认分类  ·  2025-06-23

One-Click Icon Font Generation: icon-font-generator Usage Guide

Say goodbye to tedious icon management - convert SVG icons to lightweight web fonts with command line

Why Do We Need Icon Fonts?

In web development, icon management often faces challenges:

  • Multi-resolution adaptation issues
  • Multiple small images increase HTTP requests
  • Color/size adjustments require re-exporting
  • Complex multi-color icon management

Icon fonts perfectly solve these problems: vector scaling, CSS control, single-request loading of all icons. Today's featured tool icon-font-generator can generate a complete solution with just two commands!


Quick Start

1️⃣ Install the Tool Globally

npm install -g icon-font-generator

2️⃣ Generate Icon Font

icon-font-generator C:\icons\*.svg -o dist

This command will:

  1. Read all SVG files from the C:\icons directory
  2. Generate font files (TTF/WOFF/WOFF2/EOT/SVG)
  3. Output to the dist directory and automatically create CSS/HTML preview

Core Parameters Explained

icon-font-generator [svg-path] -o [output-directory] [options]

Common Configuration Example:

icon-font-generator assets/icons/*.svg \
  -o public/fonts \
  --name "app-icons" \
  --prefix "ico-" \
  --types "woff2,woff" \
  --normalize \
  --height 1000

Key Parameters:

ParameterDescriptionDefault Value
-o, --outRequired! Output directory-
--nameFont name (affects filename)icons
--cssWhether to generate CSS filetrue
--htmlWhether to generate preview HTMLtrue
--prefixCSS class prefix (.prefix-icon)icon
--typesFont formats to generatesvg,ttf,woff,woff2,eot
--normalizeNormalize icon sizesfalse
--monoGenerate monospace fontfalse
--heightFixed font height (solves alignment)-
 
评论
硬核鸡博客 - Semple HTJi Blog. All Rights Reserved. Theme Jasmine by Kent Liao.