I
I
Igor Rodichev2019-09-12 23:18:58
gulp.js
Igor Rodichev, 2019-09-12 23:18:58

There is no automatic page refresh with browser-sync. Why?

Hello! There is no automatic page refresh with browser-sync. Moreover, the page opens in the browser, but when changes are made, it is not automatically updated. What could be the reason?

const gulp = require("gulp");
const browserSync = require("browser-sync");
const sass = require("gulp-sass");
const rename = require("gulp-rename");
const cleanCSS = require('gulp-clean-css');

// Static server
gulp.task("server", function () {
  browserSync.init({
    server: {
      baseDir: "src"
    },
    browser: 'chrome'
  });
});

gulp.task("styles", function () {
  return gulp.src("src/sass/*.+(scss|sass)")
    .pipe(sass({
      outputStyle: "compressed"
    }).on("error", sass.logError))
    .pipe(rename({
      prefix: "",
      suffix: ".min",
    }))
    .pipe(cleanCSS({compatibility: 'ie8'}))
    .pipe(gulp.dest("src/css"))
    .pipe(browserSync.stream());
});

gulp.task("watch", function () {
  gulp.watch("src/sass/*.+(scss|sass)", gulp.parallel("styles"));
  gulp.watch("/src/*.html").on("change", browserSync.reload);
});

gulp.task("default", gulp.parallel("watch", "server", "styles"));

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Kit, 2019-09-12
@ShadowOfCasper

1) var browserSync = require('browser-sync') .create();
2) In my opinion, watch().on() is from the 3rd gulp, and you obviously have the 4th here.
Take a closer look at the docks . Try to pass a separate task to watch for reload

I
Igor Rodichev, 2019-09-13
@Bubunt

Here is the solution that helped https://codepen.io/codepen-store/pen/gOYKmRw?edito...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question