Gulp Watch is not working

你说的曾经没有我的故事 提交于 2019-12-04 19:03:34

问题


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']);

});

回答1:


You've neglected to actually call the "watch" task, which is not the same thing as gulp.watch. Your default gulp task should instead look like:

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

but it should really just look like:

gulp.task('default', ['compass', 'watch']);



回答2:


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




回答3:


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'))
});


来源:https://stackoverflow.com/questions/22831490/gulp-watch-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!