对于 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/