简体   繁体   English

Gulp 4-任务未完成-Gulpfile.js Browsersync

[英]Gulp 4 - Tasks not finished - Gulpfile.js Browsersync

I'm a bit stuck with changing my old Gulp 3 Gulpfile to work in Gulp 4. 我对将旧的Gulp 3 Gulpfile更改为可在Gulp 4中使用感到有些困惑。

I have got to a point where it all seems to work except that the default and serve tasks are not marked as finished in powershell. 我已经说到一切似乎都起作用了,只是默认和服务任务没有在Powershell中标记为已完成。

How can I unblock the code and allow them to finish correctly please? 我如何解锁代码并让它们正确完成?

 var gulp = require('gulp'); var browserSync = require('browser-sync').create(); var sass = require('gulp-sass'); // Compile sass into CSS & auto-inject into browsers gulp.task('sass', function() { return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss']) .pipe(sass()) .pipe(gulp.dest("src/css")) .pipe(browserSync.stream()); }); // Move the javascript files into our /src/js folder gulp.task('js', function() { return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/popper.js/dist/umd/popper.min.js']) .pipe(gulp.dest("src/js")) .pipe(browserSync.stream()); }); // Static Server + watching scss/html files gulp.task('serve', gulp.series('sass', function() { browserSync.init({ server: "./src" }); gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass')); gulp.watch("src/*.html").on('change', browserSync.reload); })); gulp.task('default', gulp.parallel('js', 'serve')); 

The second task in your serve series doesn't return anything, gulp doesn't understand that. serve系列中的第二项任务不返回任何内容,而gulp对此不了解。 A task can return a stream or a promise - or it must call the callback parameter to signal completion, like so: 一个任务可以返回一个流或一个Promise-或者它必须调用callback参数来表示完成,如下所示:

gulp.task('serve', gulp.series('sass', function(cb) {
    // Your js task code here
    cb()
}))

Read the latest gulp4 documentation , it'll help you. 阅读最新的gulp4文档 ,它将为您提供帮助。

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

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