A
A
Alena Djukic2016-02-18 20:44:32
gulp.js
Alena Djukic, 2016-02-18 20:44:32

How to tell gulp to monitor the addition/deletion of files in a directory?

I am writing a config for gulp. I want to run the "img-min-pre" task automatically when a file is added to the ./app/img/ directory. gulp.watch, if the documentation has been correctly understood, cannot provide this. And so... How to force it to do this action, namely to monitor adding of files? Config excerpts below.

var gulp = require("gulp");
var imagemin = require("gulp-imagemin");
var pngquant = require("imagemin-pngquant");
var jpegtran = require("imagemin-jpegtran");
var liveReload = require("gulp-livereload");

gulp.task("min-img-pre", function(){
  return gulp.src("./app/img/**/*")
  .pipe(imagemin({
    progressive: true,
    svgoPlugins: [{ removeViewBox: false }],
    use: [pngquant(), jpegtran()]
  }))
  .pipe(gulp.dest("./pre/img/"))
  .pipe(liveReload());
});

gulp.task("watch", function(){
  liveReload.listen();
  gulp.watch("./app/scss/**/*.scss", ["css-pre"]);
  gulp.watch("./app/img/**/*", ["min-img-pre"]);  
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Serj-One, 2016-02-18
@Tabitha

gulp watch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question