João Serra
João Serra

Reputation: 253

Gulp imagemin not working for SVG images

Hi i have a little bit of a problem in my Gulp configuration for images, my gulp task is supposed to minify all images in the resources folder and then place the minified version in the public directory, however only the PNG images are being exported correctly...

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

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

});

That is the task that i'm running, i am currently using imagemin version ^2.4.0

Upvotes: 1

Views: 1780

Answers (1)

Guillermo
Guillermo

Reputation: 1533

Got the same issue, here is my config:

let developmentAssets   = "src",
    productionAssets    = "dist";


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

and then in your task

/* 
   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))

Hope that it helps.

Upvotes: 1

Related Questions