A Vite/Rollup plugin that combines multiple SVG files into a single SVG sprite, supporting both runtime injection and emitted file modes. Current stable version 0.6.0 requires Node >= 16, Vite >= 2.0.0, and Rollup >= 2.0.0. This ESM-only package offers customizable symbol IDs (using dirname/name variables), built-in SVGO optimization (preserving viewBox, cleaning IDs, removing dimensions/XMLNS), and flexible include/exclude patterns via @rollup/pluginutils. Compared to alternatives like vite-plugin-svg-sprite, it provides dual runtime/file modes and deeper SVGO configuration options.
npm install vite-plugin-svg-combinerVerified import paths — ran on the pinned version, not inferred.
Basic setup with runtime mode, custom symbol ID, and additional SVGO plugin.
Convert project to ESM or use dynamic import(). Ensure node >=16.
Explicitly set symbolId to '[name]' to keep current behavior.
When using baseDir, ensure include paths are relative to project root, not baseDir. Use baseDir to control how file paths map to symbol IDs.
Set svgoConfig.plugins to exclude 'cleanupIds' or add 'cleanupIds' with 'remove: false' if you need to preserve original IDs.
Use a unique string for emitFile, e.g., emitFile: 'icons/sprite.svg'.
Change to `import svgCombiner from 'vite-plugin-svg-combiner'` or use dynamic import.
Verify that the include pattern is correct and relative to project root, e.g., 'src/assets/*.svg'. Use absolute paths or adjust baseDir.
Use default import: `import svgCombiner from 'vite-plugin-svg-combiner'`.
Run `npm install -D vite-plugin-svg-combiner`.