svg-icon-baker
v1.2.0
Published
A delightful toolkit for baking raw SVG icons into delicious SVG symbol sprites
Downloads
2,868
Maintainers
Readme
svg-icon-baker
Bake the
svgicon intosymbol🍪
The core library for transforming SVG icons into optimized SVG symbol sprites.
If you like this project, please give it a Star.
Usage
import { bakeIcon, bakeIcons } from 'svg-icon-baker'
const source = { name: 'home', content: '<svg viewBox="0 0 16 16">...</svg>' }
const result = bakeIcon(source)
// result: { name: 'home', content: '<symbol id="home" viewBox="0 0 16 16">...</symbol>' }
const results = bakeIcons([source])bakeIcon and bakeIcons are synchronous.
API
bakeIcon(source: BakeSource, options?: Options): BakeResult
Convert one SVG into one symbol result.
bakeIcons(sources: BakeSource[], options?: Options): BakeResult[]
Convert multiple SVG inputs with one inferred option set.
Options
| name | type | default | description |
| ------------- | ------------- | ------- | ------------------------------------------------ |
| optimize | boolean | true | Enable default safe SVGO optimization preset. |
| svgoOptions | SvgoOptions | {} | Custom SVGO options into the optimization layer. |
Notes:
- Behavior matrix:
optimize: true+ nosvgoOptions: run default safe optimization.optimize: true+svgoOptions: run default safe optimization, then merge custom options.optimize: false+ nosvgoOptions: skip optimization layer.optimize: false+svgoOptions: run custom optimization settings only.
- When
svgoOptions.pluginsis provided, custom plugins run after default safe optimization plugins.
Type Definitions
import type { Config } from 'svgo'
type BakeSource = {
name: string
content: string
}
type BakeResult = {
name: string
content: string
}
type SvgoOptions = Pick<Config, 'multipass' | 'floatPrecision' | 'js2svg' | 'plugins'>
type Options = {
optimize?: boolean
svgoOptions?: SvgoOptions
}Features
- 🎯 Optimization: Reduce file size, and improve efficiency through
SVGO - 🔗 Reference Handling: ID and reference prefixing for sprite safety
- 🎨 Size Unify:
viewBoxpreservation or inference from root dimensions
License
MIT © yangxu52
