I have a gulp task that uses gulp -imagemin to compress images. When I add new files to this directory, I would like this task to compress them. I read that gulp.watch does not start in new files and that I should try gulp -watch, so I used it like this:
gulp.task('images', function() { watch({glob: './source/images/*'}, function (files) { return files .pipe(plumber()) .pipe(imagemin({ progressive: true, interlaced: true })) .pipe(gulp.dest('./www')); }); });
This works the same as gulp.watch on first start, but when I add a new image to the directory, nothing happens. However, if I overwrite an existing file, it starts the task again, so it behaves differently.
The documentation on gulp -watch caused this "batch mode" and said that I can also run a task for each file, so I also tried this method:
gulp.task('images', function() { gulp.src('./source/images/*') .pipe(watch()) .pipe(plumber()) .pipe(imagemin({ progressive: true, interlaced: true })) .pipe(gulp.dest('./www')); });
But nothing has changed. Why isnβt the file added to the image directory that launches the task?
gulp gulp-watch gulp-imagemin
arkanciscan
source share