jpkleemans / vite-svg-loader

Vite plugin to load SVG files as Vue components
MIT License
555 stars 59 forks source link

How to configure plugins #55

Closed soerenmartius closed 2 years ago

soerenmartius commented 2 years ago

Hi!

I am trying to configure some plugins such as cleanupIDs and prefixIds. This is my configuration but the loader returns an error [plugin:svg-loader] Plugin name should be specified

I am using the same SVGs multiple times in the same page but they won't be displayed correctly because of conflicting IDs.

# vite.config.ts
....
        svgLoader({
            svgoConfig: {
                multipass: true,
                plugins: [
                    {
                        prefixIds: {
                            prefix: ({ path }: { path: string }) => basename(path, '.svg'),
                            delim: '-',
                        },
                    },
                    { removeDoctype: true },
                    { removeComments: true },
                    { cleanupIDs: true },
                    { collapseGroups: true },
                    { removeEmptyContainers: true },
                    { removeUnknownsAndDefaults: { keepDataAttrs: false } },
                ],
            },
        }),

Could I get some advice on how to configure plugins? Many thanks!

jpkleemans commented 2 years ago

Hi, when looking at the svgo docs, it looks like you should use the following notation when registering plugins:

{
  name: 'prefixIds',
  params: {
    prefix: ({ path }: { path: string }) => basename(path, '.svg'),
    delim: '-'
  }
}

Could you try if that works?

soerenmartius commented 2 years ago

Thanks - that was helpful. Should have checked the docs myself. My apologies for the noise!

jpkleemans commented 2 years ago

You're welcome