简体   繁体   中英

imagemin not minifying SVGs

I'm using imagemin with Grunt and it works as expected with PNGs/JPGs, but not with SVGs.

When I add an SVG into my project, Grunt says:

>> File "../public/microsite/src/img/Sketch.svg" added.
Running "imagemin:dynamic" (imagemin) task
Minified 0 images (saved 0 B)

Is this simply because it can't optimise them any further, or because it's not trying to at all? Even if an SVG can't be optimised, which I doubt is the case, I'd still like it imagemin to place it in the dist folder.

This is my config:

imagemin: {
    dynamic: {
        options: {
            optimizationLevel: 3,
            svgoPlugins: [{ removeViewBox: false }]
        },
        files: [{
            expand: true,
            cwd: '../public/microsite/src/img/',
            src: ['*.{png, jpg, svg}'],
            dest: '../public/microsite/build/img/'
        }]
    }
}

I figured out the spaces in the src object were invalid. I removed them, which allowed all image files to be minified. src: ['*.*'] also works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM