使用 forEach 的任务未完成
task that uses forEach is not completing
gulp 和 javascript 都是新手。我编写的脚本返回错误(附加在 post 的末尾)
这是最小的示例文件:
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
任务已完成的信号。
gulp 和 javascript 都是新手。我编写的脚本返回错误(附加在 post 的末尾)
这是最小的示例文件:
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
任务已完成的信号。