Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp Watch is not working

I'm new Gulp user, and I try simple script to watch compass, but it didn't work. But when I just run gulp compass gulp can compile it. Any ideas? Here my script:

var gulp = require('gulp'),
    compass = require('gulp-compass'),

// Compass
gulp.task('compass', function() {
    gulp.src('./assets/scss/*.scss')
        .pipe(compass({
            config_file: './config.rb',
            css: './assets/css',
            sass: './assets/scss'
        }))
        .pipe(gulp.dest('./assets/css'));
});

// Default task
gulp.task('default', function() {
    gulp.start('compass');
});

// Watch
gulp.task('watch', function() {

    // Watch .scss files
    gulp.watch('./assets/scss/*.scss', ['compass']);

});
like image 610
Nizamil Putra Avatar asked Apr 03 '14 08:04

Nizamil Putra


People also ask

How does a gulp Watch work?

The Watch method is used to monitor your source files. When any changes to the source file is made, the watch will run an appropriate task. You can use the 'default' task to watch for changes to HTML, CSS, and JavaScript files.

What is Gulp watch command?

The watch() API connects globs to tasks using a file system watcher. It watches for changes to files that match the globs and executes the task when a change occurs. If the task doesn't signal Async Completion, it will never be run a second time.

How do you end a gulp watch?

Gulp is just running as a never ending process. The way to abort a process is Ctrl + C .


2 Answers

IN GULP 4.X

You have to pass a function. The customary way of doing this in gulp 4.x is to pass a gulp.series() invocation with only one task name. This returns a function that only executes the specified task.

gulp.task('watch', function() {
  gulp.watch('./assets/scss/*.scss', gulp.series('compass'))
});
like image 71
Nisharg Shah Avatar answered Sep 20 '22 16:09

Nisharg Shah


I changed gulp.watch source to ./assets/**/*.scss

like image 45
Nizamil Putra Avatar answered Sep 17 '22 16:09

Nizamil Putra