Categories
Uncategorized

Refresh your app automatically in the browser with gulp & livereload

Add livereload to your dev in 5 mins

You will need to install gulp-server-livereload for this. This utilizes web sockets. Make sure you have a compatible version of node+npm before you run this. This will install gulp-server-livereload as a dev dependency in your node modules folder and add it to your package.json file.

npm i gulp-server-livereload --save -D

Add the following code to gulpfile.js and run gulp livereload, it should open up your default browser and load your app at localhost:8000.
Note: Make sure you have an index.html file in your app inside the public folder.

var gulp = require('gulp');
var server = require('gulp-server-livereload');
gulp.task('livereload', function() {
  gulp.src('public')
    .pipe(server({
      livereload: true,
      directoryListing: false,
      open: true
    }));
});