简体   繁体   English

gulp手表并不总是有效

[英]gulp watch is not always working

Sometimes gulp watch is not working when I save a javascript file. 有时,当我保存JavaScript文件时,gulp watch无法正常工作。 This is my watch task below. 这是我下面的观看任务。

gulp.task('watch', function() {
    gulp.watch('./src/**/*.js', ['js']);
});

I do have a bunch of sub directories. 我确实有一堆子目录。 Would it be advisable to make my watch task be more specific like: 建议使我的监视任务更具体,例如:

gulp.task('watch', function() {
    gulp.watch('./src/*.js', ['js']);
    gulp.watch('./src/dir1/**/*.js', ['js']);
    gulp.watch('./src/dir2/**/*.js', ['js']);
});

You need to make your task slightly more specific. 您需要使您的任务更加具体。

With './src/**/*.js' you are only watching javascript files in sub folders, not in the first level of ./src/ 使用“ ./src/**/*.js”,您仅查看子文件夹中的javascript文件,而不是./src/的第一级

Having gulp.watch(['./src/**/*.js', './src/*.js'], ['js']) will work. 使用gulp.watch(['./src/**/*.js', './src/*.js'], ['js'])使用。 Keep in mind watch can take an array of strings to watch for, don't call it multiple times. 请注意,watch可以使用字符串数组进行监视,请勿多次调用。

Here's a similar question and answer: 这是一个类似的问题和答案:

How to Gulp-Watch Multiple files? 如何查看多个文件?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM