Gulps gulp.watch not triggered for new or deleted files?

前端 未结 7 1023

The following Gulpjs task works fine when editing files in the glob match:

// watch task.
gulp.task(\'watch\', [\'build\'], function () {
    gulp.watch(src          


        
7条回答
  •  臣服心动
    2020-11-27 11:34

    Globs must have a separate base directory specified and that base location must not be specified in the glob itself.

    If you have lib/*.js, it'll look under the current working dir which is process.cwd()

    Gulp uses Gaze to watch files and in the Gulp API doc we see that we can pass Gaze specific options to the watch function: gulp.watch(glob[, opts], tasks)

    Now in the Gaze doc we can find that the current working dir (glob base dir) is the cwd option.

    Which leads us to alexk's answer: gulp.watch('js/**/*.js', {cwd: src}, ['scripts']);

提交回复
热议问题