Skip to content

Add support for svgo 2.x and 3.x#224

Open
tomhughes wants to merge 1 commit intotoy:mainfrom
tomhughes:svgo-config
Open

Add support for svgo 2.x and 3.x#224
tomhughes wants to merge 1 commit intotoy:mainfrom
tomhughes:svgo-config

Conversation

@tomhughes
Copy link
Copy Markdown
Contributor

This resolves #191 by generating a configuration file for svgo if the version is 2.x or higher.

@toy
Copy link
Copy Markdown
Owner

toy commented Apr 12, 2026

Thank you for opening the PR!
My biggest concern is that same config file will be created for every optimised svg file
Also some test would be nice

@tomhughes
Copy link
Copy Markdown
Contributor Author

I've modified the patch to memoise the config file so it's only created once.

As to testing it would be nice but I'm struggling to figure out how to test it... Are there even any tests that run svgo conversions? I can see there's a test svg file but I can't see what uses it? Even then I'm not sure how you'd test that this is working let alone testing the fallback path when we only have a current svgo.

hlfan added a commit to hlfan/openstreetmap-website that referenced this pull request Apr 19, 2026
to include the new revision of toy/image_optim#224
@toy
Copy link
Copy Markdown
Owner

toy commented May 3, 2026

I tried testing how it works and understood that current solution will work only for disabling plugins included in preset-default, as enabling not included plugins (for example removeScripts) will show a warning from svgo that they are not in the preset and should be added directly to plugins to define order.

Simple way to handle this is to just list all enabled plugins after preset-default in order, but I'm not sure if it is good enough, as plugins can (and some need to) be configured. Less restrictive and more precise (but also more involved/complicated) seem to be either allowing to specify complete config as a blob, which should be ok in yaml, but cumbersome as a CLI argument, or allowing to specify config path, which splits config into two files. Or even allow both.

What do you think?

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

Successfully merging this pull request may close these issues.

Add support for SVGo 2.x

2 participants