A
A
applecode2019-02-18 18:25:54
Browsers
applecode, 2019-02-18 18:25:54

Browser-sync + gulp only reloads the page once, what's the problem?

When changing the *.twig file, the page is reloaded only once.
The console outputs [Browsersync] Reloading Browsers...
But the page does not refresh
The gulpfile.js itself

// Подключаем Gulp и все необходимые библиотеки
const { series, parallel, src, dest, watch } = require('gulp');
const style = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const browserSync = require('browser-sync').create();

//обратка стилей
function createStyle(){
    return src('catalog/view/theme/winterboots/stylesheet/stylesheet.sass')
    .pipe(style().on('error', style.logError))
    .pipe(autoprefixer(['last 15 versions']))
    .pipe(cleanCSS())
      .pipe(dest('catalog/view/theme/winterboots/stylesheet/'))
      .pipe(browserSync.stream());
};
//browser-sync
function bs(){
    browserSync.init({
    proxy: "localhost/winterboots"
    });
};
function reload(done){
    browserSync.reload();
    done();
};
//наблюдение
function watchDog(){
    watch('catalog/view/theme/winterboots/stylesheet/stylesheet.sass', series(createStyle, reload));
    watch('catalog/view/theme/winterboots/template/**/*.twig', reload);
    watch('catalog/view/theme/winterboots/image/**/*.*', reload);
    watch('catalog/view/theme/winterboots/libs/**/*', reload);  
};
exports.build = parallel(bs, watchDog);

And when changing sass files, everything works fine. What is the problem?
I've gone through everything I can.
Tried and
watch('catalog/view/theme/winterboots/template/**/*.twig').on('change', reload);
, is also useless.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galkan, 2019-02-19
@galkan

watch('catalog/view/theme/winterboots/template/**/*.twig', reload);
А для twig не видно у вас в gulpfile.js таска.

Денис Никитин, 2019-12-01
@Twine

Здравствуйте, у меня аналогичная проблема. Помогите, пожалуйста, с решением. Обновляет страницу только один раз. Ниже мой Gulp файл.

var syntax        = 'scss', // Syntax: sass or scss;
    gulpversion   = '4'; // Gulp version: 3 or 4

var gulp          = require('gulp'),
    gutil         = require('gulp-util' ),
    sass          = require('gulp-sass'),
    browserSync   = require('browser-sync'),
    concat        = require('gulp-concat'),
    uglify        = require('gulp-uglify'),
    cleancss      = require('gulp-clean-css'),
    rename        = require('gulp-rename'),
    autoprefixer  = require('gulp-autoprefixer'),
    notify        = require('gulp-notify'),
    rsync         = require('gulp-rsync');

gulp.task('browser-sync', function() {
  browserSync({
    proxy: "Gerani",
    notify: false
  });
});

gulp.task('styles', function() {
  return gulp.src('catalog/view/theme/Gerani/stylesheet/stylesheet.scss')
  .pipe(sass({ outputStyle: 'expanded' }).on("error", notify.onError()))
  .pipe(autoprefixer(['last 15 versions']))
  .pipe(cleancss( {level: { 1: { specialComments: 0 } } })) // Opt., comment out when debugging
  .pipe(gulp.dest('catalog/view/theme/Gerani/stylesheet'))
  .pipe(browserSync.stream())
});

gulp.task('reload',  function() {
    browserSync.reload();
});

if (gulpversion == 4) {
  gulp.task('watch', function() {
    gulp.watch('catalog/view/theme/Gerani/stylesheet/stylesheet.scss', gulp.parallel('styles'));
    gulp.watch('catalog/view/theme/Gerani/template/**/*.twig',  gulp.parallel('reload'))
    gulp.watch('catalog/view/theme/Gerani/js/**/*.js');
    gulp.watch('catalog/view/theme/Gerani/libs/**/*');
  });
  gulp.task('default', gulp.parallel('styles', 'browser-sync', 'watch' , 'reload'));
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question