码迷,mamicode.com
首页 > 其他好文 > 详细

gulp 3.0 & 4.0 | watch task has to be a function问题

时间:2020-07-26 00:14:30      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:导致   modules   blank   fun   optional   tar   oop   html   class   

gulpfile.js

gulp.task(watch, function () {
    gulp.watch(./css/*.css,[css]);
    gulp.watch(./html/*.html,[html]);
    gulp.watch(./image/*.*,[image]);
    gulp.watch(./js/*.cjs,[js]);
});

报错:

[14:18:45] Error: watching css/*.css: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)
    at Gulp.watch (/Users/mac/Desktop/my_project/node_modules/gulp/index.js:31:11)
    at /Users/mac/Desktop/my_project/gulpfile.js:48:10
    at taskWrapper (/Users/mac/Desktop/my_project/node_modules/undertaker/lib/set-task.js:13:15)
    at bound (domain.js:425:14)
    at runBound (domain.js:438:12)
    at asyncRunner (/Users/mac/Desktop/my_project/node_modules/async-done/index.js:55:18)
    at processTicksAndRejections (internal/process/task_queues.js:79:9)

分析:

这个是由于require引入的包的版本问题导致的。在不同的版本里,接口参数发生了变化。在gulp4.0之后已经只能接受watch第二个参数必须为函数。详情请看官网

方法一:

改版本<4.0

方法二:

gulp.task(watch, function () {
    gulp.watch(./css/*.css,gulp.series([css]));这个列表只会匹配第一个
    gulp.watch(./html/*.html,gulp.series([html]));
    gulp.watch(./image/*.*,gulp.series([image])]);
    gulp.watch(./js/*.cjs,gulp.series([js]));
});

 

 

gulp.task(watch, function () {
    gulp.watch(./css/*.css,gulp.parallel([css]));这个列表可以 支持多个元素
    gulp.watch(./html/*.html,gulp.parallel([html]));
    gulp.watch(./image/*.*,gulp.parallel([image])]);
    gulp.watch(./js/*.cjs,gulp.parallel([js]));
});

 

gulp 3.0 & 4.0 | watch task has to be a function问题

标签:导致   modules   blank   fun   optional   tar   oop   html   class   

原文地址:https://www.cnblogs.com/shenZS/p/13376624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!