Gulp 手表不工作

2022-01-12 00:00:00 node.js javascript gulp compass-sass

我是 Gulp 的新用户,我尝试使用简单的脚本来查看指南针,但它不起作用.但是当我运行 gulp compass 时,gulp 可以编译它.有任何想法吗?这是我的脚本:

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

});

推荐答案

你忽略了实际调用watch"任务,这和 gulp.watch 不是一回事.您的默认 gulp 任务应如下所示:

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

但它应该看起来像:

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

相关文章