gulp-watch + browserSync.reload doesn't work
See original GitHub issueMy case:
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var browserSync = require('browser-sync');
var reload = browserSync.reload;
gulp.task('browser-sync', function() {
browserSync({
proxy: {
target: '127.0.0.1:3000'
}
});
});
gulp.task('scss', function() {
return buildCSS();
});
gulp.task('watch:scss', function() {
return buildCSS(true)
.on('data', function(file) {
//console.log(file);
})
.pipe(reload({
stream: true
}));
});
gulp.task('watch', ['watch:scss', 'browser-sync']);
function buildCSS(watching) {
var pattern = 'public/scss/*.scss';
var task = gulp.src(pattern);
if (watching) {
task = $.watch(pattern, {
emit: 'all',
verbose: true
})
}
return task
.pipe($.sass())
.pipe(gulp.dest('public/styles'));
}
When watch:scss
before browser-sync
, the browser doesn’t reload when file is changed.
gulp.task('watch', ['watch:scss', 'browser-sync']);
But when tweak they positions, it’s working. Why?
gulp.task('watch', ['browser-sync', 'watch:scss']);
I have no idea. How to understand that behaviour?
Maybe https://github.com/floatdrop/gulp-watch/issues/142 same as this.
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
browser-sync does not refresh page after changes with Gulp
This is because you're calling browserSync.reload on the html watch and not on the scss watch. Try this: gulp.watch("app/scss/*.scss", ...
Read more >Browsersync + Gulp.js
Browsersync makes your browser testing workflow faster by synchronising URLs, interactions and code changes across multiple devices.
Read more >Gulp 4 - BrowserSync and Auto Reload - YouTube
Gulp 4 - BrowserSync and Auto Reload. Watch later. Share. Copy link. Info. Shopping. Tap to unmute. If playback doesn't begin shortly, ...
Read more >BrowserSync not refreshing - Laracasts
Upon running gulp watch the connection gets initialised so BrowserSync is installed and working. However it doesn't seem to pick up on any...
Read more >Quick setup for Gulp 4 + Browsersync + Sass - Coder Coder
It works by spinning up a local server and syncing it up to your browser. Then, anytime you make a change in your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you checked http://www.browsersync.io/docs/#requirements
Ok, I’ve discovered something! This was in my html:
and this is how it looks after BS processing:
Virtual hostname was ‘mclinic’, just like the theme name occurring in the path to the stylesheet. So I think it’s a bug.