@applecode

Browser-sync + gulp перезагружает страницу только один раз, в чем проблема?

При изменении файла *.twig страница перезагружается только один раз.
В консоли выводится [Browsersync] Reloading Browsers...
Но страница не обновляется
Сам gulpfile.js
// Подключаем 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);

Причем при изменении sass файлов, все работает отлично. В чем проблема?
Перерыл уже все что можно.
Пробовал и
watch('catalog/view/theme/winterboots/template/**/*.twig').on('change', reload);
, тоже бесполезно.
  • Вопрос задан
  • 389 просмотров
Пригласить эксперта
Ответы на вопрос 2
galkan
@galkan
watch('catalog/view/theme/winterboots/template/**/*.twig', reload);
А для twig не видно у вас в gulpfile.js таска.
Ответ написан
Комментировать
Здравствуйте, у меня аналогичная проблема. Помогите, пожалуйста, с решением. Обновляет страницу только один раз. Ниже мой 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'));
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы