F
F
Fedya2019-07-31 23:37:43
JavaScript
Fedya, 2019-07-31 23:37:43

How to make gulp imagemin take different image formats and put them in different folders?

task

function image() {
  return gulp.src('./source/img/**/*.{jpg,png,gif}')
    .pipe(imagemin([
      imagemin.gifsicle({interlaced: true}),
      imagemin.jpegtran({progressive: true}),
      imagemin.optipng({optimizationLevel: 3}),
      imagemin.svgo({
        plugins: [
            {removeViewBox: true},
            {cleanupIDs: false}
        ]
      })
    ]))
    
    .pipe(gulp.dest('./build/img/'))
};


Tell me how to make gulp-imagemin take .jpg, .png, gif files from ./source/img/, put them in ./build/img/ , and take .svg files from ./source/svg and put them in ./build/svg/ ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2019-07-31
@FedyaAsker

Create separate tasks for raster and vector formats, in which to specify the desired end paths

I
inkShio, 2019-07-31
@inkShio

try this gulpIf
and then something
like .pipe(gulpIf('*.png', gulp.dest('img/png')));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question