Gulp – Web Server

Gulp, Gulp – Web Server

We can actually serve our webpages by using a gulp plugin.

1
$ npm install gulp-webserver --save-dev

For more information about gulp-webserver check out https://www.npmjs.com/package/gulp-webserver

gulpfile.js
1
2
3
4
5
6
7
...
var webserver = require('gulp-webserver');
...
gulp.task('webserver', function() {
  return gulp.src('build')
    .pipe(webserver());
});

Now when we run our gulp task webserver we will have a local webserver to view our website.

1
2
3
4
5
6
$ gulp webserver

Using gulpfile ~/YOUR_DIRECTORY/gulpfile.js
Starting 'webserver'...
Webserver started at http://localhost:8000
Finished 'webserver' after 20 ms

If you go to http://localhost:8000 in your web browser you should see our index.html page saying Hello Gulp!.