A
A
Azat S.2015-09-06 08:47:12
gulp.js
Azat S., 2015-09-06 08:47:12

How to use gulp-imagemin with gulp-watch?

Can I use the gulp-imagemin plugin with gulp-watch?
It is necessary that the images are minified as soon as they are loaded into the folder.
Snippet of my gulpfile.js:

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');

gulp.task('default', function() {
  gulp.watch('dist/images/**', function(event) {
    gulp.run('images');
  });
});

// Image files

gulp.task('images', function () {
    return gulp.src('src/images/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()]
        }))
        .pipe(gulp.dest('dist/images'));
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Дмитрий Королёв, 2015-09-07
@azat-io

Судя по коду, вы используете не плагин gulp-watch, а встроенный gulp.watch. Отличие в том, что встроенный не умеет следить за новыми и удалёнными файлами. Воспользуйтесь gulp-watch, он всё умеет.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question