gulp.watch没有捕获新文件

时间:2015-04-21 10:30:43

标签: javascript coffeescript gulp

我有以下gulpfile

var gulp = require('gulp');
var clean = require('gulp-clean');
var rename = require('gulp-rename');
var coffee = require('gulp-coffee');
var cache = require('gulp-cached');
var path = require('path');

var dist = './Test/public/';
var assets = './Test/assets/';

var paths = {
    coffee: ['./**/*.coffee']
};

var coffeeTask = function () {
        console.log('coffeeTask');
        return gulp.src(paths.coffee, { cwd: assets + '**' })
            .pipe(cache('coffee'))
            .pipe(coffee({ bare: true }))
            .pipe(rename({
                extname: ".coffee.js"
            }))
            .pipe(gulp.dest(dist));
};

gulp.task('clean', function() {
    return gulp.src(dist)
        .pipe(clean());
});

gulp.task('coffee', ['clean'], coffeeTask);
gulp.task('coffee-watch', coffeeTask);

gulp.task('build', ['clean', 'coffee']);

gulp.task('watch', ['build'], function() {
    var w = gulp.watch(paths.coffee, ['coffee-watch']);
    w.on('change', function(evt) {
        console.log(evt);
    });
});

gulp.task('default', ['build']);

此配置的关键点是使用与部署和监视进程相同的任务(阅读“构建”和“监视”任务)。

问题是监视任务没有捕获任何新的咖啡文件。编辑或删除的咖啡文件处理得很好。根据以下issue它应该有效。原因是什么?

1 个答案:

答案 0 :(得分:0)

使用gulp-watch模块解决:

watch(paths.coffee, function(evt) {
    gulp.start('coffee-watch');
});

问题是如何删除资产文件夹中dist文件夹中删除的文件?