Gulp.watch does not execute task

Asked

Viewed 121 times

0

Introducing

I’m using Gulp to automate my tasks, I’m using Gulp.watch to preprocess the Sass as soon as I see a change in the file:

gulp.task('styles', function(){
        return gulp.src(files)
        .pipe(sass({style: 'expanded'}))
        .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
        .pipe(gulp.dest('css'))
        .pipe(rename({suffix:'.min'}))
        .pipe(minifycss())
        .pipe(gulp.dest('css'));
    });

 gulp.task('watch', function() {
     gulp.watch('sass/*.scss', ['styles']);
 });

Starting the tasks

gulp.task('default', ['express', 'watch'], function() {

});

On the console

$ Gulp

Run the server correctly but my 'watch' task does not pre-process ( just doesn’t happen nd ), if I go straight to task gulp watch it works properly.

Working

To work

gulp.task('watch', function() {
    gulp.watch('sass/*.scss', function(){
        gulp.start('styles');
    });
}); 

Problem

I wonder what the problem would be for gulp.watch do not work just by passing the parameters as I saw several examples. Thus leaving the code cleaner.

gulp.watch('sass/*.scss', ['styles']);
  • Did you get this to work? It would be interesting to have an answer here to help others...

  • I had to create 2 watch one for the root file of the Sass folder (.scss) and the other to other files inside the folders (/.scss)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.