iconify-svgo-loader
v1.0.3
Published
Iconify loader optimized using SVGO, Works perfectly with @unocss/preset-icons or unplugin-icons.
Downloads
10
Readme
iconify-svgo-loader
Ionify loader optimized using SVGO, Works perfectly with @unocss/preset-icons or unplugin-icons.
Normal use: default loading of presets and monochrome icon processing, prefixIds
import FileSystemSvgoLoader from 'iconify-svgo-loader'
const loader1 = FileSystemSvgoLoader('./src/assets/fonts', {/* options */})
Custom Callback mode to obtain name and svg content
import FileSystemSvgoLoader from 'iconify-svgo-loader'
const loader2 = FileSystemSvgoLoader('./src/assets/fonts', (name, svgContent) => {
return {
/* options */
}
})
Complete example:handling monochrome icons, and adding prefixIds
import FileSystemSvgoLoader, { prefixIds, presetDefault, sortAttrs, convertColors } from 'iconify-svgo-loader'
const loader3 = FileSystemSvgoLoader('./src/assets/fonts', (name, svgContent) => {
// is single color
const single = patch('fill', svgContent) + patch('stop-color', svgContent) === 1
const plugins = [
// set of built-in plugins enabled by default
presetDefault(),
// enable built-in plugins by name
prefixIds({ prefix: name }),
// or by expanded notation which allows to configure plugin
sortAttrs({ xmlnsOrder: 'alphabetical' }),
]
if (single)
plugins.push(convertColors({ currentColor: true }))
return {
multipass: true,
plugins: plugins
}
})
function patch(re: string, s: string) {
return s.split(re).length - 1
}