0

Can't set my gulp+livereload server to restart and update page on change of JS files. How could i implement it?

Here's my gulpfile.js:

var gulp        = require('gulp'),
    livereload  = require('gulp-livereload'),
    watch       = require('gulp-watch'),
    express     = require('express'),
    app         = express(),
    path        = require('path'),
    server      = tinylr();

 ...
gulp.task('js', function() {
  return gulp.src([
  'app/scripts/*.js',
    ])
    .pipe( concat('combined.js'))
    .pipe( gulp.dest('../dist/app/js/'))
    .pipe( livereload( server ));
});

gulp.task('watch', function () {
...
  gulp.watch(['app/scripts/*.js'],['js']);   
});
  • possible duplicate of [gulp.js livereload with express server?](http://stackoverflow.com/questions/23665993/gulp-js-livereload-with-express-server) – Preview Oct 12 '14 at 10:49
  • You may want to use [BrowserSync](http://www.browsersync.io) (instead of express, gulp-livereload, tinylr) - it's a dev server with built-in livereload feature as well some other goodies. And for the watch you may want to use built-in `gulp.watch` method instead of `gulp-watch` plugin. – Konstantin Tarkus Oct 16 '14 at 22:35
  • Thank you, Konstantin, i'll give it a try! – walkthroughthecode Oct 18 '14 at 18:50

1 Answers1

0

Use livereload.reload() instead of livereload() and don't forget to install browser extension and add livereload script to your page (with src="//localhost:35729/livereload.js?snipver=1" by default)

zhekaus
  • 3,126
  • 6
  • 23
  • 46