【问题标题】:Gulp imagemin not working for SVG imagesGulp imagemin 不适用于 SVG 图像
【发布时间】:2016-10-15 04:17:12
【问题描述】:

嗨,我的 Gulp 图像配置有一点问题,我的 gulp 任务应该缩小资源文件夹中的所有图像,然后将缩小版本放在公共目录中,但是只有 PNG 图像正在正确导出...

gulp.task('images', function() {

    gulp.src(assets + 'images/**')
            .pipe(imagemin({
                progressive: true,
                optimizationLevel: 7,
                svgoPlugins: [{removeViewBox: false}],
                use: [pngquant()]
            }))
            .pipe(gulp.dest(public + 'images/'));

});

这是我正在运行的任务,我目前正在使用 imagemin 版本 ^2.4.0

【问题讨论】:

    标签: svg gulp gulp-imagemin imagemin


    【解决方案1】:

    遇到同样的问题,这是我的配置:

    let developmentAssets   = "src",
        productionAssets    = "dist";
    
    
    module.exports = {
       optimize : {
        images: {
            src:  developmentAssets + '/img/**/*.{jpg,jpeg,png,gif,svg}',
            options: {
                optimizationLevel: 3,
                progessive: true,
                interlaced: true
            }
          }
       }
    };
    

    然后在你的任务中

    /* 
       This is my particular setting to have everything organized
       read this amazing gulp tutorial: http://stefanimhoff.de/2014/gulp-tutorial-12-optimize-css-javascript-images-and-html/ 
    */
    
    config      = require('./gulp/config'),
    configImg   = config.optimize.images,
    
    
    .pipe(imagemin(configImg.options))
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 2016-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多