Gulp – Live Reload

Gulp, Gulp – Live Reload

So far so good, lets link our css file in index.html.

/contents/index.html
1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html>
  <head>
    <title>Learning Gulp</title>
    <link rel="stylesheet" href="/styles/main.min.css" />
  </head>
  <body>
    <h1>Hello Gulp!</h1>
  </body>
</html>

Now let’s turn on live reload with our gulp-webserver.

gulpefile.js
1
2
3
4
gulp.task('webserver', function() {
  return gulp.src('build')
    .pipe(webserver({ livereload: true }));
});

If we run gulp webserver in one terminator and gulp watch in another, we will have our webserver running and live refreshing on each build.

terminator1:

1
$ gulp webserver

terminator2:

1
$ gulp watch

Update the css file to:

/contents/styles/some_styles.css
1
2
3
h1 {
  color: blue;
}

Go to http://localhost:8000 to watch our webpage.