1.0.3 • Published 4 months ago

iconify-svgo-loader v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

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
}
1.0.2

4 months ago

1.0.3

4 months ago

1.0.1

6 months ago

1.0.0

1 year ago