gpt4 book ai didi

javascript - Gulp 4 迁移错误(您是否忘记发出异步完成信号?)

转载 作者:行者123 更新时间:2023-11-30 12:02:54 25 4
gpt4 key购买 nike

我有一个 gulp 3 文件,我正在尝试将其升级到 gulp 4。当我这样做时,一些任务可以工作,而其他任务则不能。我得到的三个错误如下:

简洁风格:

gulp.task('clean-styles', function (done) {
var files = config.temp + '**/*.css';
clean(files, done);
});

[23:47:05] The following tasks did not complete: clean-styles
[23:47:05] Did you forget to signal async completion?

scss-观察者:

gulp.task('scss-watcher', function () {
gulp.watch([config.scss], ['styles']);
});

[23:51:27] 'scss-watcher' errored after 2.46 ms
[23:51:27] Error: watching ./src/client/styles/styles.scss: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)

样式:(如果我删除 clean-styles 系列,这将起作用)

gulp.task('styles', gulp.series('clean-styles', function () {
log('Compiling SCSS --> CSS');

return gulp
.src(config.scss)
.pipe($.scss())
.pipe($.autoprefixer({ browsers: ['last 2 versions', '> 5%'] }))
.pipe(gulp.dest(config.temp));
}));

[23:52:42] The following tasks did not complete: styles, clean-styles
[23:52:42] Did you forget to signal async completion?

审查:(有效)

gulp.task('vet', function () {
log('Analyzing source with ESLint');
return gulp
.src(config.js)
.pipe($.if(args.verbose, $.print()))
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failOnError());
});

功能:

function clean(path, done) {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, done);
}

function log(msg) {
if (typeof(msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
}
else {
$.util.log($.util.colors.blue(msg));
}
}

我一定是遗漏了什么。任何人都可以填补我所缺少的东西吗?

最佳答案

简洁风格

del不带回调函数。它返回一个 Promise,你必须在你的任务中返回:

function clean(path) {
log('Cleaning: ' + $.util.colors.blue(path));
return del(path);
}
gulp.task('clean-styles', function () {
var files = config.temp + '**/*.css';
return clean(files);
});

scss-watcher

gulp.watch() 不再支持任务名称数组。你必须向它传递一个函数,gulp.series()gulp.parallel():

gulp.task('scss-watcher', function () {
gulp.watch([config.scss], gulp.series('styles'));
});

样式

应该与上面对 clean-styles 的更改一起工作。

关于javascript - Gulp 4 迁移错误(您是否忘记发出异步完成信号?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com