3

I'm trying to use gulp-live-server to automatically restart my server and refresh the page whenever my code changes.

Here is the basic setup I have:

On my server.js:

app.use(require('connect-livereload')());

My gulp file:

gulp.task('server', function () {
   server = gls('app.js', options);
    server.start();

    // Watch for file changes
    gulp.watch(['app.js', 'app/**/*.js', 'config/**/*.js', 'components/**/*.jsx'], function() {
        server.start.bind(server)();
        server.notify.bind(server)();
    });
});

My server successfully does restart, but the browser does not refresh ever.

Help is appreciated.

Kousha
  • 32,871
  • 51
  • 172
  • 296

1 Answers1

3

Try by passing the file when calling notify:

gulp.task('server', function () {
   server = gls('app.js', options);
    server.start();

    // Watch for file changes
    gulp.watch(['app.js', 'app/**/*.js', 'config/**/*.js', 'components/**/*.jsx'], function(file) {
        server.start.bind(server)();
        server.notify.bind(server)(file);
    });
});
Maluen
  • 1,753
  • 11
  • 16
  • 1
    I can't believe those commands are nowhere in the entire internet, but here on this least known SO post. It literally would never refresh for me. Thanks so much! – Trip Sep 29 '16 at 12:32
  • 1
    PAGE NOT REFRESHING WITH THIS SCRIPT :( – ShibinRagh Nov 30 '17 at 14:31