简体   繁体   English

Gulp 4 你忘了发出异步完成信号吗?

[英]Gulp 4 Did you forget to signal async completion?

I am trying to build my sass with gulp sass and i get the error:我正在尝试使用 gulp sass 构建我的 sass,但出现错误:

The following tasks did not complete: build, clean Did you forget to signal async completion?以下任务未完成:构建、清理您是否忘记发出异步完成信号?

gulp.task('clean', function() { return del.sync('dist'); });

 gulp.task('build', gulp.series('clean', 'imagemin', 'sass', 'js', function(done) {

var buildMain = gulp.src([
    'app/*.html',
    'app/.htaccess'
]).pipe(gulp.dest('dist'));

var buildCss = gulp.src([
    'app/css/main.min.css'
    ])
.pipe(gulp.dest('dist/css'));

var buildJs =  gulp.src([
    'app/js/scripts.min.js'
    ])
.pipe(gulp.dest('dist/js'));

var buildFonts = gulp.src([
    'app/fonts/**/*'
    ])
.pipe(gulp.dest('dist/fonts'));
done(); }));

Like Sven Schoenung said in this question :正如Sven Schoenung在这个问题中所说:

This is a much more fitting mechanism for your use case.这是一种更适合您的用例的机制。 Note that most of the time you won't have to create the Promise object yourself, it will usually be provided by a package (eg the frequently used del package returns a Promise).请注意,大多数时候您不必自己创建 Promise 对象,它通常由一个包提供(例如,经常使用的 del 包返回一个 Promise)。

I tried this approach and for me is working.我尝试了这种方法,对我来说很有效。 The code will be:代码将是:

gulp.task('clean:dist', function (resolve) {
  del.sync('dist');
  resolve();
})

For the latest version of gulp you can use:对于最新版本的 gulp,您可以使用:

export const build = series(clean, imagemin, sass, js);

No additional wrapper function needed.不需要额外的包装函数。

https://gulpjs.com/docs/en/api/series/#usage https://gulpjs.com/docs/en/api/series/#usage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM