Gulp:必须在Gulp.set中指定任务函数

6
当我尝试运行gulp时,我遇到了以下标题错误。
我的gulpfile.js文件:
    var gulp = require('gulp'),
        connect = require('gulp-connect-php'),
        gulpPhpunit = require('gulp-phpunit');

    gulp.task('gulpPhpunit', function() {
      var options = {debug: false};
      gulp.src('phpunit.xml') 
    .pipe(phpunit('./vendor/bin/phpunit',options));
    });

    gulp.task("default", ["gulpPhpunit"]);

错误
    // error
    assert.js:42
      throw new errors.AssertionError({
      ^

    AssertionError [ERR_ASSERTION]: Task function must be specified
        at Gulp.set [as _setTask] (/var/www/html/wptest2/node_modules/undertaker/lib/set-task.js:10:3)
        at Gulp.task (/var/www/html/wptest2/node_modules/undertaker/lib/task.js:13:8)
        at Object.<anonymous> (/var/www/html/wptest2/gulpfile.js:26:6)
        at Module._compile (module.js:652:30)
        at Object.Module._extensions..js (module.js:663:10)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)
        at Function.Module._load (module.js:497:3)
        at Module.require (module.js:596:17)
        at require (internal/module.js:11:18)

"必须指定任务函数",难道我的gulpPhpunit引用不正确吗?此代码是从文档(示例2)复制出来的。
1个回答

9
如果您使用的是gulp v4,语法已经发生了变化。您可以降低gulp版本或更改代码的某些部分以运行新的gulp版本:
var gulp = require('gulp'),
    connect = require('gulp-connect-php'),
    gulpPhpunit = require('gulp-phpunit');

gulp.task('gulpPhpunit', function (done) {
    // var options = {debug: false};
    gulp.src('phpunit.xml')
        .pipe(phpunit('./vendor/bin/phpunit', options));

    done();
});

gulp.task("default", gulp.series('gulpPhpunit'));

更新内容包括done回调函数和gulp.series()部分。

详情请参考按顺序运行任务


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接