-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
prefixIds: { true } generates prefix__prefix__cls-1 class names #1148
Comments
@patrick-wc: The root of these issues is that there is no built-in plugin testing for CLI and plugin invocations. I have to set up a test case manually and try to reproduce this bug. Just invoking the svgo CLI works fine: <svg width="120" height="120" xmlns="http://www.w3.org/2000/svg">
<rect class="test" x="10" y="10" width="100" height="100"/>
<rect class="" id="test" x="10" y="10" width="100" height="100"/>
</svg>
<svg width="120" height="120" xmlns="http://www.w3.org/2000/svg"><path class="test_svg__test" d="M10 10h100v100H10z"/><path d="M10 10h100v100H10z"/></svg>
The used prefix I have to set up a manual |
@patrick-wc: So I set up a test in my fork for
Sorry, no better way for replacing
|
@patrick-wc: So after some testing with that branch it seems that
So there are three ways for making this work: Make file path pass through
|
Wouldn't it be sufficient checking if the prefix which will be added already exists in the unprefixed id/class? |
@wesselbaum: I still have to find out why there are SVGs are passed to |
I won't disagree on this one for this issue. |
@wesselbaum: Yes, it seems reasonable. There is a catch though: What if, by chance, the classes start with something that should be also as the prefix? If in that case the prefix is skipped, there is no guarantee that there are no collisions between other SVG files that had no prefix and are then prefixed. So what do you think about an extra option that can be still turned off, Edit: This explains why a SVG is passed multiple files to |
Sounds good to me. I appreciate your work a lot. Thanks! |
@wesselbaum:
Depending on how your Gulp setup uses Please try this fix and report whether it works in your setup. |
Sadly I can't try it until next week but I will report my results as soon as possible. Thanks. |
I just noticed that flagging each processed node isn't the best solution. |
The |
@wesselbaum: A new approach is used now that adds For trying out the fix (PR) before it is merged, see my previous post with updated instructions. |
Fixed in 2.0.1 |
Thanks very much to @strarsis for creating the plugin, I was having to manually change class names before using this which was awful. However when I use this plugin with gulp-imagemin I can't get the filename to be passed into the output svg filename.
If I use this config (which from reading around this repo seems to be the way that is suggested, there is no documentation).
The output file SVG class names (or IDs) are changed from "cls-1" to "prefix__prefix__cls-1" or in one file I noticed "Layer_2" being changed to "prefix__prefix__prefix__Layer_2"
If I use it with this config, (prefix part copied from @ming-codes )
The output described above changes from "cls-1" to "id-125__id-111__cls-1" and "id-391__id-373__Layer_2" which although slightly off means I don't get any issues with the same SVGs sharing the same class names which makes them all screw up when inlining them on a page.
It still seems like something is being passed twice as there are repeated values (
prefix__prefix__
andid-#__id-#
) which is similar to this issue, but I don't think I'm using multipass. I'm not sure why, it's probably my mistake on the configuration arguments but this has taken me a while to get working so I'm hoping this helps someone else.I am using the latest versions of gulp (4.0.2) and gulp-imagemin (6.1.0) on Windows 10 with Windows Subsystem Linux (WSL to help people out in future when searching).
Please let me know if I'm supposed to use prefixIds with some kind of function call other than true to get the filename coming through, I'm happy to provide more info if needed.
The text was updated successfully, but these errors were encountered: