A Vite plugin that generates webfonts (WOFF2, WOFF, TTF, EOT) from SVG icon files at build time. Current stable version is 7.0.0, released April 2026 with a major breaking change: the internal generator was rewritten from @vusion/webfonts-generator to a native Rust core, changing font binary output and the cssContext callback signature. The plugin exposes a virtual CSS module that can be imported directly into your app, supporting class-based icon usage. It requires Vite ^6.0.0 || ^7.0.0 || ^8.0.0 and Node ^20 || ^22 || >=24. Differentiators: tight Vite integration, zero-config setup, and high-performance Rust-based generation compared to slower Node.js alternatives.
npm install vite-svg-2-webfontVerified import paths — ran on the pinned version, not inferred.
Configures the plugin to read SVG icons from an 'icons' folder, generates WOFF2/WOFF, and imports the virtual CSS.
Regenerate fonts after upgrading; font files from v6 are not binary-compatible with v7. Consider versioning font outputs.
Update custom cssContext callbacks to use the new single-argument signature. See migration guide.
Switch to `import` syntax or use dynamic import().
Avoid relying on preloadFormats in v6; use explicit <link rel="preload"> instead.
Upgrade Node.js to a supported version (20, 22, or 24+).
Mock the virtual module in test environments using vitest's `vi.mock` or Vite's `resolve.alias`.
Change to `import viteSvgToWebfont from 'vite-svg-2-webfont'` or use dynamic `import()`.
Use `import viteSvgToWebfont from 'vite-svg-2-webfont'` (without curly braces).
Change cssContext from (tpl, options, handlebars) => ... to (singleArg) => ... where singleArg includes tpl.
Ensure the directory exists and the path is correct (use `resolve()` with absolute path).