Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gulp 在其他任务之后使用browserSync.stream()_Gulp_Gulp Browser Sync - Fatal编程技术网

Gulp 在其他任务之后使用browserSync.stream()

Gulp 在其他任务之后使用browserSync.stream(),gulp,gulp-browser-sync,Gulp,Gulp Browser Sync,当我像这样使用stream()方法时,效果很好: var gulp = require('gulp'), watch = require('gulp-watch'), browserSync = require('browser-sync').create(); gulp.task('watch', function () { browserSync.init({ notify: false, server: {

当我像这样使用
stream()
方法时,效果很好:

    var gulp = require('gulp'),
    watch = require('gulp-watch'),
    browserSync = require('browser-sync').create();

gulp.task('watch', function () {

    browserSync.init({
        notify: false,
        server: {
            baseDir: "app"
        }
    });       

    watch('./app/assets/styles/**/*.css', gulp.series('cssInject'));
});

    gulp.task('cssInject',  function () {
        return gulp.src('./app/temp/styles/styles.css').pipe(browserSync.stream());

    });
在执行
stream()
之前添加另一个任务时,仅完成该任务

gulp.task('cssInject', gulp.series('styles'), function () {
        return gulp.src('./app/temp/styles/styles.css').pipe(browserSync.stream());
        });
然后,控制台输出:

[15:16:00] Starting 'cssInject'...
[15:16:00] Starting 'styles'...
[15:16:00] Finished 'styles' after 50 ms
[15:16:00] Finished 'cssInject' after 53 ms
但是CSS没有被注入,只有在手动重新加载后才会应用更改

我注意到他们使用了一些语法不同的过时软件包:例如,
task()
的第二个参数设置为数组:
['styles']
。它不起作用,我发现您应该使用
series()
paralell()


有一个看起来和我的一样,但我没有找到我的问题的答案,因为我是一个新手用户

解决者:将cssInject定义为单独的
task()
,然后将其作为第二个参数放入
series()

gulp.task('cssInject', function () {
    return gulp.src('./app/temp/styles/styles.css').pipe(browserSync.stream());
});

gulp.task('manageCSS', gulp.series('styles', 'cssInject'));