Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

?url export option bypasses svgo #124

Open
frederikheld opened this issue Jun 16, 2023 · 9 comments
Open

?url export option bypasses svgo #124

frederikheld opened this issue Jun 16, 2023 · 9 comments

Comments

@frederikheld
Copy link

frederikheld commented Jun 16, 2023

The nuxt-svgo docs don't mention this feature, but the vite-svg-loader docs do: it is possible to import a svg as a file url (instead of embedding it into the source of the page) and it works with nuxt-svgo as well. I use this feature to generate an optimized version of the svg to use it as favicon.

Unfortunately this option seems to bypass the optimization through svgo. The default import embeds an optimized version of the svg into the source code, but the url import generates a file that is exactly the same as the asset that went in. Is this on purpose? Is there any way to have the optimization with the url import? Unfortunately the vite-svg-loader docs only mention that it is possible, but neither how it works inside nor how it can be configured...

I fiddled around with the svgoConfig option of nuxt-svgo but couldn't find any working configuration. Any ideas?

@jd1378
Copy link
Collaborator

jd1378 commented Jun 16, 2023

looking at the source it does not support optimizing the ?url import, because there's a built-in ?url handler: https://vitejs.dev/guide/assets.html#explicit-url-imports

but since we are handling the import before that, we can probably simply url encode it ourselves and not rely on vite's functionality, this should be easy I guess.
but it will be a breaking change, because it can potentially break it for anyone who is relying on it, what do you think @cpsoinos ? should we release it as a breaking change or as minor if we are going to do so ?

I'll work on it when I have time, not sure if I can do this week

@frederikheld
Copy link
Author

Thanks for considering adding this feature :-)

Maybe keep the current behavior as default and add a config option that allows to run url imports through svgo optimization? This would avoid the breaking change ...

@jd1378
Copy link
Collaborator

jd1378 commented Jun 16, 2023

hmm, good idea, thanks!

@jd1378
Copy link
Collaborator

jd1378 commented Jun 17, 2023

.... simply url encode it ourselves ...

I was really tired and I see that I misunderstood the feature lol
what ?url does is that it gives the url for that file, not url encode it (what I originally thought it was)

I have to rethink how to do it, and how feasible it is

@frederikheld
Copy link
Author

frederikheld commented Jul 5, 2023

I guess I would be happy with the url encoded version as well, if it can be used as a favicon ...

@jd1378
Copy link
Collaborator

jd1378 commented Jul 5, 2023

sorry, I didn't have access to my laptop for around 1.5 weeks
I'll get to it soon

url encoded version probably can be done quite easily, but not sure about how the direct url to optimized file works, so will put that for a later time

@jd1378
Copy link
Collaborator

jd1378 commented Jul 5, 2023

I have released the url_encode query feature @frederikheld
let me know if there's any issue
I have updated the readme to include a note about it as well

@jd1378
Copy link
Collaborator

jd1378 commented Jul 7, 2023

@frederikheld did you manage to test it ?

@frederikheld
Copy link
Author

frederikheld commented Jul 10, 2023

I've seen that you implemented it, thanks a lot, that's awesome. However I did not find the time to test it as I have to take care of a different project atm. As soon as i get back to this project, I'll let you know if something doesn't work as expected :-) Thanks again for providing a solution so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants