pivanov / vite-plugin-svg-sprite

1 stars 1 forks source link

<defs> are not extracted from SVGs into inline SVG before <symbols> #1

Open dsine-de opened 1 month ago

dsine-de commented 1 month ago

Hi,

this line doesn't seem to do anything: https://github.com/pivanov/vite-plugin-svg-sprite/blob/e9106479866e98dba41e9ef8d001910ad58a4d4a/src/index.ts#L109

It seems to look for <defs> tags in $svg.children() to extract them and put them before any other <symbol> tags of the sprite SVG - but this is a newly created empty cheerio variable (new SVG element), right?

dsine-de commented 1 month ago

Seems the problem is that after the line $symbol.append($svg.children()); the $svg variable contains an empty SVG without children, so the next line const $defs = $svg.find('defs'); will never contain the <defs> tag

pivanov commented 1 month ago

Seems the problem is that after the line $symbol.append($svg.children()); the $svg variable contains an empty SVG without children, so the next line const $defs = $svg.find('defs'); will never contain the <defs> tag

Nice :) if you have idea for PR please feel free to open one :) I will try to check it soon

dsine-de commented 1 month ago

I don't know why the <defs> are being extracted to be honest - <defs> should work if they are inside the individual <symbol> tags (with the style fix for chromium browsers described in #2).

pivanov commented 1 month ago

I don't know why the <defs> are being extracted to be honest - <defs> should work if they are inside the individual <symbol> tags (with the style fix for chromium browsers described in #2).

The issue is if you use the sprite as external svg file. But we should think to make it better.