0.9.1 • Published 9 years ago

gulp-webserver v0.9.1

Weekly downloads
12,215
License
MIT
Repository
github
Last release
9 years ago

gulp-webserver Build Status npm.io npm.io

Streaming gulp plugin to run a local webserver with LiveReload

Hint: This is a rewrite of gulp-connect

Install

$ npm install --save-dev gulp-webserver

Usage

The gulp.src('root') parameter is the root directory of the webserver. Multiple directories are possible.

var gulp = require('gulp');
var webserver = require('gulp-webserver');

gulp.task('webserver', function() {
  gulp.src('app')
    .pipe(webserver({
      livereload: true,
      directoryListing: true,
      open: true
    }));
});

Options

KeyTypeDefaultDescription
hostStringlocalhosthostname of the webserver
portNumber8000port of the webserver
pathString/path to the webserver
livereloadBoolean/Objectfalsewhether to use livereload. For advanced options, provide an object. You can use the 'port' property to set a custom live reload port and the filter function to filter out files to watch. The object also needs to set enable property to true (e.g. enable: true) in order to activate the livereload mode. It is off by default.
directoryListingBoolean/Objectfalsewhether to display a directory listing. For advanced options, provide an object with the 'enable' property set to true. You can use the 'path' property to set a custom path or the 'options' property to set custom serve-index options.
fallbackStringundefinedfile to fall back to (relative to webserver root)
openBoolean/Stringfalseopen the localhost server in the browser. By providing a String you can specify the path to open (for complete path, use the complete url http://my-server:8080/public/) .
httpsBoolean/Objectfalsewhether to use https or not. By default, gulp-webserver provides you with a development certificate but you remain free to specify a path for your key and certificate by providing an object like this one: {key: 'path/to/key.pem', cert: 'path/to/cert.pem'}.
middlewareFunction/Array[]a connect middleware function or a list of middleware functions
proxiesArray[]a list of proxy objects. Each proxy object can be specified by {source: '/abc', target: 'http://localhost:8080/abc', options: {headers: {'ABC_HEADER': 'abc'}}}.

FAQ

Why can't I reach the server from the network?

Solution: Set 0.0.0.0 as host option.

How can I use html5Mode for my single page app with this plugin?

Solution: Set the index.html of your application as fallback option. For example:

gulp.task('webserver', function() {
  gulp.src('app')
    .pipe(webserver({
      fallback: 'index.html'
    }));
});

How can I pass a custom filter to livereload?

Solution: Set enable: true and provide filter function in filter: property of the livereload object. For example:

gulp.task('webserver', function() {
  gulp.src('app')
    .pipe(webserver({
      livereload: {
        enable: true, // need this set to true to enable livereload
        filter: function(fileName) {
          if (fileName.match(/.map$/)) { // exclude all source maps from livereload
            return false;
          } else {
            return true;
          }
        }
      }
    }));
});

How can I kill the running server?

Solution: Either by pressing Ctrl + C or programmatically like in this example:

var stream = gulp.src('app').pipe(webserver());
stream.emit('kill');

License

MIT License

0.9.1

9 years ago

0.9.0

10 years ago

0.8.8

10 years ago

0.8.7

10 years ago

0.8.6

10 years ago

0.8.5

10 years ago

0.8.4

10 years ago

0.8.3

10 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.2

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago