简体   繁体   English

imagemin不会缩小SVG

[英]imagemin not minifying SVGs

I'm using imagemin with Grunt and it works as expected with PNGs/JPGs, but not with SVGs. 我在Grunt上使用imagemin ,它可以与PNG / JPG一起使用,但不能与imagemin一起使用。

When I add an SVG into my project, Grunt says: 当我在项目中添加SVG时,Grunt说:

>> 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. 即使无法优化SVG(我怀疑是这种情况),我仍然希望将它imagemin放置在dist文件夹中。

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. 我发现src对象中的空格无效。 I removed them, which allowed all image files to be minified. 我删除了它们,从而使所有图像文件都可以缩小。 src: ['*.*'] also works. src: ['*.*']也可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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