gulp任务在手动调用时有效,但在gulp.watch调用时会抛出错误

时间:2015-11-18 15:31:09

标签: javascript gulp

我正在使用的内置方法gulp.watch来监视我的Javascript文件中的更改。

这是buildJs任务定义:

gulp.task('buildJs', function() {
    var combined = combiner.obj([
        gulp.src([
            './bower_components/jquery/dist/jquery.min.js',
            './bower_components/knockout/dist/knockout.js',
            './bower_components/lodash/lodash.min.js',
            paths.dev.js + '**/*.js'
        ]),
        sourcemaps.init(),
        concat('all.js'),
        sourcemaps.write('.'),
        rename('all.min.js'),
        gulp.dest(paths.pub.js)
    ]);

    combined.on('error', console.error.bind(console));
    return combined;
}); 

当我手动调用gulp buildJs时,无论是否应该创建的文件(all.min.js)已经存在,所有内容都像魅力一样:

gulp buildJs
[16:21:40] Using gulpfile c:\src\portal\branches\octopus-working\Modules\gulpfile.js
[16:21:40] Starting 'buildJs'...
[16:21:40] Finished 'buildJs' after 124 ms

Process finished with exit code 0

当我将此任务分配给观察者时,它似乎正确地调用buildJs任务,但这次有不同的结果:

gulp watchJs
[16:15:44] Using gulpfile c:\src\portal\branches\octopus-working\Modules\gulpfile.js
[16:15:44] Starting 'watchJs'...
[16:15:44] Finished 'watchJs' after 16 ms
[16:15:56] Starting 'buildJs'...
{ [Error: UNKNOWN: unknown error, open 'c:\src\portal\branches\octopus-working\Modules\Static\Portal\js\all.min.js']
  errno: -4094,
  code: 'UNKNOWN',
  syscall: 'open',
  path: 'c:\\src\\portal\\branches\\octopus-working\\Modules\\Static\\Portal\\js\\all.min.js' }
[16:15:56] 'buildJs' errored after 107 ms
[16:15:56] Error: UNKNOWN: unknown error, open 'c:\src\portal\branches\octopus-working\Modules\Static\Portal\js\all.min.js'
    at Error (native)

这是我的手表定义:

gulp.task('watchJs', function() {
    gulp.watch(paths.dev.js + '**/*.js', ['buildJs']);
});

只是为了完整起见,这是我的paths对象:

var paths = {
    dev: {
        scss: './assets/styles/',
        js: './assets/scripts/',
        html: './Templates/__DEV_static_html/'
    },
    pub: {
        css: './Static/Portal/css',
        js: './Static/Portal/js',
        html: './Static/Portal'
    }
};

那么为什么在手动调用时会起作用,而在gulp.watch调用时却不起作用?

0 个答案:

没有答案