sindresorhus / gulp-imagemin

Minify PNG, JPEG, GIF and SVG images
MIT License
1.9k stars 157 forks source link

Incorrect SVGO prefix with prefixIds #343

Closed johnkhughes closed 4 years ago

johnkhughes commented 4 years ago

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 here, the prefix output in the SVG files is prefix. Here is the relevant part of the script I am using:

return gulp.src('./src/*.svg')
    .pipe(imagemin([
        imagemin.svgo({
            plugins: [
                {
                    prefixIds: {
                        prefix: true
                    }
                }
            ]
        })
    ]))
    .pipe(gulp.dest('./dist'));

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 work with Gulp here?

sindresorhus commented 4 years ago

This needs to be opened on https://github.com/imagemin/imagemin-svgo. I think await svgo.optimize(buffer); needs to be changed to await svgo.optimize(buffer, {path: somePath});, but it's not clear where somePath would come from as Imagemin doesn't pass the path to plugins.