question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gulp-watch + browserSync.reload doesn't work

See original GitHub issue

My 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:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
shakyShanecommented, Mar 21, 2015
0reactions
OnkelTemcommented, Mar 22, 2015

Ok, I’ve discovered something! This was in my html:

link(href="/sites/default/themes/mclinic/css/styles.css", media="screen", rel="stylesheet")

and this is how it looks after BS processing:

<link href="/sites/default/themes/localhost:3000/css/styles.css" media="screen" rel="stylesheet">

Virtual hostname was ‘mclinic’, just like the theme name occurring in the path to the stylesheet. So I think it’s a bug.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found