A
A
arturios5712018-12-18 15:13:19
gulp.js
arturios571, 2018-12-18 15:13:19

How to cure [Browsersync] Reloading Browsers... (buffered 4 events)?

Hello! There are such sections of code!

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: 'app'
        }
    });
    browserSync.watch('app/**/*.*').on('change', browserSync.reload);
});

gulp.task('html', function () {
    return gulp.src(path.src.html) 
        .pipe(gulp.dest(path.app.html))
        .pipe(browserSync.reload({
            stream: true
        }));
});

gulp.task('watch', function () {
    gulp.watch(path.src.html, gulp.series('html'));
});

gulp.task('default', gulp.series(
    gulp.parallel('watch', 'browser-sync') //запускаем паралельно слежку за файлами и синхронизацию браузера
));

I run the default command
As a result of the work in the logs
[14:59:51] Starting 'default'...
[14:59:51] Starting 'watch'...
[14:59:51] Starting 'browser-sync'...
[Browsersync] Access URLs:
 -------------------------------------
       Local: http://localhost:3000
    External: http://192.168.1.92:3000
 -------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 -------------------------------------
[Browsersync] Serving files from: app
[14:59:57] Starting 'html'...
[Browsersync] 2 files changed (404.html, index.html)
[14:59:57] Finished 'html' after 66 ms
[Browsersync] Reloading Browsers... (buffered 4 events)

The changes are all ok, watch sees the changes and updates the files, the browser automatically opens to localhost:3000
But...
[Browsersync] Reloading Browsers... (buffered 4 events)

the browser hangs and does not update, even Google does not want to help ..
I don’t understand why it falls into the buffer and how to avoid it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mitya Kolesnikov, 2020-06-16
@mittus

The code is incorrect, change tracking does not need to be scattered in different places, the browser update is written in the series, and not in the task. In gulp 4, the update will work correctly with this spelling:

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: 'app'
        }
    });
});

gulp.task('html', function () {
    return gulp.src(path.src.html) 
        .pipe(gulp.dest(path.app.html));
});

gulp.task('watch', function () {
    gulp.watch('app/**/*.*').on('change', browserSync.reload);
    gulp.watch(path.src.html).on('change', gulp.series(html, browserSync.reload));
});

gulp.task('default', gulp.series(
    gulp.parallel('watch', 'browser-sync') //запускаем паралельно слежку за файлами и синхронизацию браузера
));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question