Registry / devops / vite-svg-to-ico

vite-svg-to-ico

JSON →
library3.1.5jsnpmunverified

Vite plugin that converts SVG (and PNG, JPEG, WebP, AVIF, GIF, TIFF) input into multi-size .ico favicons at build time with HMR support during development. Version 3.1.5 requires Node >=22.18.0 and uses sharp for image processing. Differentiators: multi-format emit (ICO, PNG, SVG) with per-spec injection control, automatic <link> tag deduplication, remote URL support, and a CLI tool for generating favicons standalone.

npm install vite-svg-to-ico
INSTALL
IMPORT
SIG · VITE-SVG-TO-ICO
V
vite-svg-to-ico
devopsjavascriptv3.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

svgToIco
import svgToIco from 'vite-svg-to-ico'
const svgToIco = require('vite-svg-to-ico')
ESM-only package; CommonJS require will fail. If using TypeScript, ensure 'esModuleInterop' is enabled if needed (default export).
svgToIco default export
import svgToIco from 'vite-svg-to-ico'
import { svgToIco } from 'vite-svg-to-ico'
The package has a default export only. Named import will result in undefined.
vite.config.ts type annotation
import svgToIco from 'vite-svg-to-ico'; export default defineConfig({ plugins: [svgToIco({ input: 'src/icon.svg' })] })
const svgToIco = require('vite-svg-to-ico');
TypeScript users should import directly; no typings package needed.
CLI usage
npx -y --package=vite-svg-to-ico svg-to-ico generate input.svg --out-dir ./public
npx vite-svg-to-ico generate input.svg --out-dir ./public
CLI is accessed via the 'svg-to-ico' subcommand, not the package name.

Configures vite-svg-to-ico with a multi-format emit array for ICO, PNG, and SVG outputs with HTML injection.

// Install: npm install -D vite-svg-to-ico // vite.config.ts import { defineConfig } from 'vite'; import svgToIco from 'vite-svg-to-ico'; export default defineConfig({ plugins: [ svgToIco({ input: 'src/favicon.svg', emit: [ { format: 'ico', sizes: [16, 32, 48], inject: true }, { format: 'png', sizes: [192, 512], inject: { sizes: [192] } }, { format: 'svg', filename: 'favicon.svg', inject: true }, ], }), ], }); // Build generates: // - favicon.ico (16, 32, 48) // - favicon-192x192.png, favicon-512x512.png // - favicon.svg (copy) // HTML gets <link> tags injected, existing icon links removed.
Debug
Known issues
breakingv3 changed 'emit' from an object to an array of per-format specs.
fix
Migrate from { source, sizes, inject } to [{ format, sizes?, filename?, inject? }] as documented in README. The v2 shape still works with deprecation warning but will be removed in v4.
affects: >=3.0.0 <4.0.0
breakingNode.js >=22.18.0 required since v3.
fix
Upgrade Node.js to >=22.18.0 or use v2.x of the package (not recommended).
affects: >=3.0.0
deprecatedLegacy v2 'emit' shape ({ source, sizes, inject }) triggers deprecation warning and will be removed in v4.
fix
Switch to array-based emit as shown in README.
affects: >=3.0.0 <4.0.0
gotchaSVG format emit only works when input is SVG; for raster inputs, the SVG spec is silently ignored.
fix
Check input format when including { format: 'svg' } in emit array; ensure source is actually SVG.
affects: >=3.0.0
gotchaWhen inject: true is set on any emit spec, all existing <link rel='icon'> and <link rel='shortcut icon'> tags are removed; apple-touch-icon tags are preserved.
fix
If you need to keep custom icon links, avoid inject: true and manually add links.
affects: >=1.0.0
gotchaRemote/URL input is fetched once per build and cached; HMR only watches local paths.
fix
For development, use local files to get HMR updates on source changes.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'vite-svg-to-ico'
Package not installed or missing from devDependencies.
fix
npm install -D vite-svg-to-ico
ERR_REQUIRE_ESM: require() of ES Module /node_modules/vite-svg-to-ico/dist/index.mjs from vite.config.ts not supported.
Using CommonJS require() on ESM-only package.
fix
Change to 'import svgToIco from 'vite-svg-to-ico'' in an ESM context (vite.config.ts is ESM by default).
TypeError: svgToIco is not a function
Named import instead of default import (e.g., import { svgToIco } from ...).
fix
Use default import: import svgToIco from 'vite-svg-to-ico'
Error: sharp is not installed
sharp is a required peer dependency; may fail in some CI environments.
fix
npm install sharp (or add it explicitly to dependencies).
Upgrade
Version history
3.1.5latest on npm
Audit
Dependencies
sharprequiredUsed for image conversion (SVG to PNG rasterization and resizing). Required runtime dependency installed automatically.
Agent activity
2 hits · last 30 days
node
2
Resources
vite-svg-to-ico — npm install vite-svg-to-ico · libregistry