M
M
Michael2018-12-24 14:47:09
gulp.js
Michael, 2018-12-24 14:47:09

Gulp 4: set up automatic page refresh?

Good afternoon.
Today I personally encountered the problem of the updated "gulp". It just so happened that I set myself version 4 ... And away we go. A lot of mistakes, everything is stupid, slows down, lags.
But I was not at a loss, I read the solutions. This one was especially helpful: https://stackoverflow.com/questions/39665773/gulp-...
And no more errors. There literally brackets [ ] should be changed.
But auto update doesn't work. That is, I write changes to the sass file, but compilation to css does not occur. If the problem was in the sass task, shouldn't I get an error?
I feel like the problem is somewhere here:

gulp.task('watch', gulp.series('browser-sync', 'sass', function() {
  gulp.watch('app/sass/**/*.sass', gulp.series('sass'));
}));

And here is the whole code:
var gulp        = require('gulp'),
  sass        = require('gulp-sass'),
  browserSync = require('browser-sync');

gulp.task('sass', function() {
  return gulp.src('app/sass/**/*.sass')
  .pipe(sass())
  .pipe(gulp.dest('app/css'))
  .pipe(browserSync.reload({stream: true}))
});

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


gulp.task('watch', gulp.series('browser-sync', 'sass', function() {
  gulp.watch('app/sass/**/*.sass', gulp.series('sass'));
}));

Need your help
PS It is necessary that when you run gulp watch, with any changes, the page is automatically updated and shows the result.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leha Lucker, 2019-12-29
@LehaLucker

Might come in handy for someone. Before making any edits, check if you have a body tag on your page. I accidentally forgot it and stopped updating. Stupid mistake, but you can break the brain. )))

C
coderxx, 2018-12-24
@coderxx

Try like this:

gulp.task('watch', gulp.parallel('browser-sync', 'sass', function() {
  gulp.watch('app/sass/**/*.sass', gulp.parallel('sass'));
}));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question