提示: Error: watching index.html: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)
解释:
从gulp4.0开始,watch函数的第二个参数必须是函数。
即以前的写法不再支持。
以前的这种写法
Gulp.watch(“监听的文件”,[任务名字符串])
不能再使用了,必须这样
Gulp.watch(“监听的文件”,回调函数)。
示例:
以前的这种写法:
gulp.task("copy-index",async ()=>{
gulp.src("index.html")
.pipe(gulp.dest("D:\\phpStudy\\WWW\\web1809\\taobao"));
});
gulp.task("watch-all",async ()=>{
gulp.watch("index.html",["copy-index"]);
});
不支持了,
必须这样写:
gulp.task("watch-all",async ()=>{
gulp.watch("index.html",async ()=>{
gulp.src("index.html")
.pipe(gulp.dest("D:\\phpStudy\\WWW\\web1809\\taobao"));
});
});
即把以前对应任务的回调函数写在watch函数的第二参数里。