-
Notifications
You must be signed in to change notification settings - Fork 29
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
Incorrect SVGO prefix with prefixIds #41
Comments
@johnkhughes How did you overcome this ? Is it fixed ? Facing same issue |
The short answer is that I didn't overcome it and it isn't fixed. Right now, I am optimizing my images separately, outside of my gulp tasks. Sorry I can't be much more help. |
cool @johnkhughes . Actually I need id in my symbol tag while creating svg sprite so have used |
The issue is that the So to resolve this, either:
From what I can see from the documentation, these might not be viable, though. If you're alright with not using the filename as the prefix, an alternative solution is to use the A config like one of these should work for you, feel free to make the prefix longer to reduce risk of collisions: const crypto = require('crypto');
const options = {
plugins: [
{
name: "prefixIds",
params: {
delim: "",
prefix: () => crypto.randomBytes(20).toString('hex').slice(0, 2)
}
}
]
}; const options = {
plugins: [
{
name: "prefixIds",
params: {
delim: "",
prefix: () => Math.floor(Math.random() * 99).toString()
}
}
]
}; More info: https://svgo.dev/docs/plugins/prefix-ids/#parameters |
I originally opened this issue on gulp-imagemin but was advised it should be opened here instead.
SVGO lets you set a prefix for id attributes with the prefixIds option. If this is option is set, the default prefix should be the SVG file name. However, when the option is set in gulp-imagemin, the prefix output in the SVG files is
prefix
. Here is the relevant part of the script I am using:My aim was to have the id attributes in each file have a unique prefix to avoid naming collisions when they are embedded in an HTML file. Is there any way to get the default, documented behaviour of SVGO to work here?
The text was updated successfully, but these errors were encountered: