javascript - 使用 forEach 的任务未完成

标签 javascript gulp

对于 gulp 和 javascript 来说都是相当陌生的。我编写的脚本返回错误(附加在帖子末尾。)

这是最小的示例文件:

const {src, dest, series, parallel }= require('gulp');
const sourceList = ['about', 'contact', 'projects'];

// Next 2 functions take each html file and move them to respective dist folder.

function eachHtml(){
  sourceList.forEach(function(htmlFile){
    cphtmlTask(`source/${htmlFile}/${htmlFile}.html`, `dist/${htmlFile}/`)
  });
  //cphtmlTask('source/index.html', 'dist/');
}

function cphtmlTask(i,o){
  return src(i)
    .pipe(dest(o));
}

exports.default = series(eachHtml);

输出

[17:55:19] Starting 'default'...
[17:55:19] Starting 'eachHtml'...
[17:55:19] The following tasks did not complete: default, eachHtml
[17:55:19] Did you forget to signal async completion?

请问有什么帮助吗?

最佳答案

我认为您需要的是:

function eachHtml(cb){

  sourceList.forEach(function(htmlFile){
    cphtmlTask(`source/${htmlFile}/${htmlFile}.html`, `dist/${htmlFile}/`)
  });

  cb();

 //cphtmlTask('source/index.html', 'dist/');
}

cb 是一个回调函数,它将向 gulp 发出信号,表明 eachHtml 任务已完成。

关于javascript - 使用 forEach 的任务未完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60439208/

相关文章:

Gulp-Shell没有执行任何命令

javascript - svg 缩放时的滚动条

php - 使用 Gulp 和 Livereload 创建一个运行 PHP 的服务器

javascript - 如何在 Vue 中对包含 2 个字段的数组进行排序?

javascript - 如何正确地将 react 导入到 node-webkit 应用程序中?

javascript - 如何在 Gulp 中使用 Jadeify

javascript - 让 Stylus 将导入的 CSS 合并到样式表中

javascript - Gulp 中的任务依赖关系

javascript - AngularJS:在组件之间进行通信的最佳实践是什么?

javascript - php echo 将html输出为文本