M
M
Moe Green2015-04-19 21:08:38
gulp.js
Moe Green, 2015-04-19 21:08:38

Gulp-imagemin - Doesn't track a folder if it's initially empty?

Good day to all!
Question for Javascript and Gulp.js connoisseurs.
It consists in the following.
There is a Gulp Task created to optimize images:

var gulp = require('gulp'),
      plumber = require('gulp-plumber'),
      browserSync = require('browser-sync'),
      imagemin = require('gulp-imagemin');

// IMAGE OPTIMIZE
gulp.task('imageminTask', function(){
  gulp.src(['app/images/*.{png,jpg,gif}', '!sprite/*'])
    .pipe(plumber())
    .pipe(imagemin({
      optimizationLevel: 3,
      interlaced: true,
      progressive: true
}))
   .pipe(gulp.dest('build/images/'));
});

// WATCH
gulp.task('watchTask', function(){
gulp.watch('app/templates/**/*.jade', ['jadeTask']);
gulp.watch('app/styles/**/*.styl', ['stylusTask']);
gulp.watch('app/scripts/**/*.js', ['javascriptTask']);
gulp.watch('app/images/*.{png,jpg,gif}', ['imageminTask']);
});

// DEFAULT
gulp.task('default', ['jadeTask', 'stylusTask', 'javascriptTask', 'imageminTask', 'browserSyncTask', 'watchTask']);

The strange behavior of this task is that it monitors the appearance of imagesnew images in the directory and starts the actions prescribed in it only in one case - if at the initial start imagesthere was already at least one image in the directory .
If the directory imageswas empty at the initial start of the task , then the task does not track the appearance of new images in it and does not perform its actions , respectively.
Very strange behavior, which in theory should not be.
Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
felixexter, 2015-04-20
@mQm

Use gulp-watch.
stackoverflow.com/questions/22391527/gulps-gulp-wa...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question