I have a Jekyll site which is part of a Gulp project, using BrowserSync to preview the site as it is built. One of my watch
statements looks for changes to the html
in order to auto-refresh the site.
gulp.watch('docs/_site/**/*.html').on('change', browserSync.reload);
Works as designed.
However, when I update header.html
(or any other shared file) the browser is refreshed multiple times because all the pages changed. This makes sense, since all the static pages are being updated. But I'd like to prevent this when updating a shared file.
Is there a way I can tell Gulp/BrowserSync to only refresh once when a shared Jekyll file is updated?
UPDATE
My watch set looks like the following:
gulp.task('dev:watch', ['browserSync', 'docs:sass', 'docs:lib', 'docs:build'], function () {
gulp.watch(['scss/**/*.scss', 'docs/assets/**/*.scss'], ['dev:sass']);
gulp.watch(['docs/**/*.html', 'docs/**/*.md', '!docs/_site/**'], ['docs:build']);
gulp.watch('docs/_site/**/*.html').on('change', browserSync.reload);
});
The docs:build
task:
gulp.task('docs:build', function () {
browserSync.notify('Building Jekyll');
return spawn('jekyll', ['build', '--config', '_config.yml,_config_dev.yml', '--incremental'], {stdio: 'inherit'});
});