Search code examples
javascriptnode.jsgulpgulp-livereload

gulp-live-server doesn't refresh page


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.


Solution

  • 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);
        });
    });