Javascript 正在执行gulp 4的gulp watch任务

Javascript 正在执行gulp 4的gulp watch任务,javascript,node.js,gulp,Javascript,Node.js,Gulp,我升级到Gulp4,需要更好地了解如何运行正在进行的监视任务以及如何使任务异步运行。我正在用于重新加载任务 当我开始尝试运行gulpfile时,它抛出了一个关于异步完成的错误。看起来是这样的: // templating task gulp.task('html', function() { return gulp.src('views/**/*.html') .pipe(livereload()); }); //styles build/minification gulp.t

我升级到Gulp4,需要更好地了解如何运行正在进行的监视任务以及如何使任务异步运行。我正在用于重新加载任务

当我开始尝试运行gulpfile时,它抛出了一个关于异步完成的错误。看起来是这样的:

// templating task
gulp.task('html', function() {
    return gulp.src('views/**/*.html')
    .pipe(livereload());
});

//styles build/minification
gulp.task('styles', function() {
    return sass('client/scss/styles.scss', {
        noCache: true,
        style: 'compressed'
    })
    .pipe(cleanCSS())
    .pipe(gulp.dest('public/build/stylesheets'))
    .pipe(livereload());
});

gulp.task('scripts', function() {
    gulp.src('client/js/script.js')
    .pipe(webpack(require('./webpack.config.js')))
        .pipe(uglify())
    .pipe(gulp.dest('public/build/javascripts'))
    .pipe(livereload());
});

// uses livereload
gulp.task('watch', function() {
  livereload.listen();
    gulp.watch('views/**/*.html', ['html']);
  gulp.watch('client/scss/*.scss', ['styles']);
    gulp.watch('client/js/**/*.js', ['scripts']);
});

gulp.task('server', function () {
    // Start the server at the beginning of the task
    server.run(['./bin/www']);
});
我的默认任务是:

//default task
gulp.task(
    'default', 
        gulp.series('html', 'styles', 'scripts', 'watch', 'server')
);
这引发了:

[10:37:30]使用gulpfile/site/gulpfile.js[10:37:30] 正在启动“默认”。。。[10:37:30]正在启动“html”。。。[10:37:30] 80毫秒[10:37:30]后完成“html”,开始“样式”。。。[10:37:31] 在1.24秒[10:37:31]开始“脚本”后完成“样式”。。。 [10:37:33]版本:网页1.15.0 资产大小Chunks Chunk Names scripts.min.js 17.7 kB 0[emissed]main[10:37:33]以下任务未完成:默认设置,脚本[10:37:33]是否忘记发出信号 异步完成

我找到了答案,因此我将代码更改为:

//default task
gulp.task('default', function(done) {
    gulp.series('html', 'styles', 'scripts', 'watch', 'server');
    done();
});
其中包括:

[10:59:08] Using gulpfile /site/gulpfile.js
[10:59:08] Starting 'default'...
[10:59:08] Finished 'default' after 2.06 ms
但它看起来只是…跳过了一切,我的所有资产都没有编译,我的监视任务也从未开始。它说:

3.x升级通知gulp livereload不会自动侦听更改。您现在必须手动调用livereload.listen,除非您 设置选项“开始”:

livereload({start:true})

这不会启动实时重新加载


如何在Gulp 4.0中运行正在进行的监视任务并使任务运行?

可能您已经遇到过此任务。但分享它会有所帮助。。。