1

这是我的gulpfile.js

var gulp = require('gulp');
var clean = require('gulp-clean');

var DEST_BASE = 'dist';
var JADE_TASK = 'jade';
var JADE_SRC = 'app/**/ui/*.jade';
var JADE_DEST = DEST_BASE + '/dist/app';

gulp.task(JADE_TASK, function() {
    return gulp.src(JADE_SRC).pipe(gulp.dest(JADE_DEST));
});

gulp.task('clean', function() {
    return gulp.src(DEST_BASE, {read: false}).pipe(clean());
});

gulp.task('default', ['clean'], function() {
    gulp.start(JADE_TASK);
});

gulp.task('watch', ['default'], function(){
    gulp.watch(JADE_SRC, JADE_TASK);
});

它所做的只是将文件从一个目录复制到另一个目录。当我跑

gulp

它按预期复制文件。当我跑

gulp watch

default按预期运行任务。当我修改源文件时,出现以下错误:

<PROJECT_ROOT>\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\index.js:17
      if(cb) cb(outEvt);
             ^
TypeError: string is not a function
    at Gaze.<anonymous> (<PROJECT_ROOT>\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\index.js:17:14)
    at Gaze.EventEmitter.emit (events.js:98:17)
    at Gaze.emit (<PROJECT_ROOT>\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:120:32)
    at <PROJECT_ROOT>\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:393:16
    at StatWatcher._pollers.(anonymous function) (<PROJECT_ROOT>\node_modules\gulp\node_modules\vinyl-fs\node_modules\glob-watcher\node_modules\gaze\lib\gaze.js:316:7)
    at StatWatcher.EventEmitter.emit (events.js:98:17)
    at StatWatcher._handle.onchange (fs.js:1104:10)

除了使用 Windows 之外,我做错了什么吗?(编辑:可在 OS X 中重现)

4

1 回答 1

6

to 的第二个参数gulp.watch应该是数组或函数,而不是(如您的情况)字符串。

所以改用这个:

gulp.watch(JADE_SRC, [ JADE_TASK ]);
于 2014-02-04T08:10:59.833 回答