【问题标题】:GulpJS can no longer finds task in list properly (Gulp 4)GulpJS 不能再正确地在列表中找到任务(Gulp 4)
【发布时间】:2019-10-03 13:42:18
【问题描述】:

我的 gulp 文件看起来像这样(简化)

function copyAssets () {
  return src(paths.assets, { base: './' })
    .pipe(cache('asset-files'))
    .pipe(dest(paths.build))
}

// Some more task functions

const build = parallel(copyAssets, brewCoffee, buildTypescript)

module.exports = { build, watch: series(build, watchFiles) }

但现在当我列出它时,它看起来像:

[15:29:30] Tasks for .....
[15:29:30] ├─┬ <parallel>
[15:29:30] │ └─┬ <parallel>
[15:29:30] │   ├── copyAssets
[15:29:30] │   ├── brewCoffee
[15:29:30] │   └── buildTypescript
[15:29:30] └─┬ <series>
[15:29:30]   └─┬ <series>
[15:29:30]     ├─┬ <parallel>
[15:29:30]     │ ├── copyAssets
[15:29:30]     │ ├── brewCoffee
[15:29:30]     │ └── buildTypescript
[15:29:30]     └── watchFiles

运行gulp build 之类的东西会说该任务不存在。

如果我将系列/并行函数包装在一个匿名函数中,我确实会看到它出现在列表中(就像这样)

const build = () => parallel(copyAssets, brewCoffee, buildTypescript)
module.exports = { build, watch: () => series(build, watchFiles) }

但是当我运行gulp build 时,我得到了

Did you forget to signal async completion?

作为一个错误。

我知道在某些时候这确实有效(几个月前)。但现在由于某种原因它不再。如果我运行gulp --version,则输出为:

CLI version: 2.2.0
Local version: 4.0.0

编辑:嗯。这似乎有效

module.exports = { build: () => build(), watch: () => series(build, watchFiles)() }

但我怀疑我实际上应该如何做这些事情......

edit2:不,仍然损坏,它现在运行,并等待完成。然后说和之前一样的错误:The following tasks did not complete: build

【问题讨论】:

  • brewCoffeebuildTypescriptwatchFiles的返回值是多少?
  • 答案已更新

标签: javascript node.js build gulp system


【解决方案1】:

当我过去使用并行(非常简短)时,我不得不从 gulp 中引用它。

例如变化:

const build = () => parallel(copyAssets, brewCoffee, buildTypescript);

到:

const build = () => gulp.parallel(copyAssets, brewCoffee, buildTypescript);

这里的系列也一样:

module.exports = { build, watch: gulp.series(build, watchFiles) }

【讨论】:

    【解决方案2】:

    试试这个:

    var srcPaths = {
        app: [
            'wwwroot/app/**/*.ts'
        ],
        js: [
            'node_modules/core-js/client/shim.min.js',
            'node_modules/zone.js/dist/zone.js',
            'node_modules/reflect-metadata/Reflect.js',
            'node_modules/systemjs/dist/system.src.js',
            'node_modules/typescript/lib/typescript.js',
            'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js',
            'node_modules/moment/moment.js'
        ],
    }
    
    gulp.task('watch', function () {
        gulp.watch([srcPaths.app, srcPaths.js], gulp.series('js'));
    });
    

    它会正常工作的。享受吧!

    【讨论】:

    • 据我所知,这是“旧”v3 语法。哪个确实有效,但澄清不是我想要的,但谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多