jpkleemans / vite-svg-loader

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

?raw skips svg optimization #84

Closed jdratx closed 1 year ago

jdratx commented 1 year ago

First of all, thank you for creating this! <3 Second: I'm unsure if this is an issue or more of a feature request. According to the readme 'SVGs can be imported as strings using the ?raw suffix'

As I wasn't using the ?skipsvgo suffix and svg optimization is enabled in the config, I initially assumed this would still include svg optimization. And therefore I thought it would output the results of the optimization as a string, but that's not the case. The string is the content of the original file, unoptimized despite svg optimization settings.

I used an SVG with original file size of 500kb With ?raw it remains 500kb Without it, as a component, it's 312kb

I ran svgo on top of the string after loading it with the ?raw suffix and then it will become 312kb. Therefore my conclusion svg optimization isn't done while using ?raw suffix.

Would love this as a feature: to be able to import an optimized svg as a string. Maybe changing the behavior of ?raw is too confusing and should remain as it is, and this should be more like ?string with a note in the docs that this is as a string, but optimized?

gkatsanos commented 1 year ago

Yes, that's not an issue. : https://github.com/jpkleemans/vite-svg-loader/blob/main/index.js#L36-L38 raw skips optimization. changing the raw behavior would break backwards compatibility, as raw means raw and not optimized :-) Not sure if we have capacity to add this as a feature, but feel free to open up a PR! I'm helping the core maintainer and I'll happily review your PR.