Gulp plugin to run a webserver (with LiveReload)
npm install gulp-connectgulp-connect    
==============
> Gulp plugin to run a webserver (with LiveReload)
gulp-connect is sponsored by JetBrains!
```
npm install --save-dev gulp-connect
`js
var gulp = require('gulp'),
connect = require('gulp-connect');
gulp.task('connect', function() {
connect.server();
});
gulp.task('default', ['connect']);
`
#### LiveReload
`js
var gulp = require('gulp'),
connect = require('gulp-connect');
gulp.task('connect', function() {
connect.server({
root: 'app',
livereload: true
});
});
gulp.task('html', function () {
gulp.src('./app/*.html')
.pipe(gulp.dest('./app'))
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['./app/*.html'], ['html']);
});
gulp.task('default', ['connect', 'watch']);
`
#### Start and stop server
`js`
gulp.task('jenkins-tests', function() {
connect.server({
port: 8888
});
// run some headless tests with phantomjs
// when process exits:
connect.serverClose();
});
#### Multiple server
`js
var gulp = require('gulp'),
stylus = require('gulp-stylus'),
connect = require('gulp-connect');
gulp.task('connectDev', function () {
connect.server({
name: 'Dev App',
root: ['app', 'tmp'],
port: 8000,
livereload: true
});
});
gulp.task('connectDist', function () {
connect.server({
name: 'Dist App',
root: 'dist',
port: 8001,
livereload: true
});
});
gulp.task('html', function () {
gulp.src('./app/*.html')
.pipe(gulp.dest('./app'))
.pipe(connect.reload());
});
gulp.task('stylus', function () {
gulp.src('./app/stylus/*.styl')
.pipe(stylus())
.pipe(gulp.dest('./app/css'))
.pipe(connect.reload());
});
gulp.task('watch', function () {
gulp.watch(['./app/*.html'], ['html']);
gulp.watch(['./app/stylus/*.styl'], ['stylus']);
});
gulp.task('default', ['connectDist', 'connectDev', 'watch']);
`
#### http2 support
If the http2 package is installed and you use an https connection to gulp connect then http 2 will be used in preference to http 1.
#### options.root
Type: Array or StringDirectory with gulpfile
Default:
The root path
#### options.port
Type: Number8080
Default:
The connect webserver port
#### options.host
Type: Stringlocalhost
Default:
#### options.name
Type: StringServer
Default:
The name that will be output when the server starts/stops.
#### options.https
Type: Objectfalse
Default:
Can be any options documented at https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
When https is just set to true (boolean), then internally some defaults will be used.
#### options.livereload
Type: Object or Booleanfalse
Default:
#### options.livereload.port
Type: Number35729
Default:
Overrides the hostname of the script livereload injects in index.html
#### options.livereload.hostname
Type: String
Default: 'undefined'
#### options.fallback
Type: Stringundefined
Default:
Fallback file (e.g. index.html)
#### options.middleware
Type: Function[]
Default:
#### options.debug
Type: Booleanfalse
Default:
#### options.index
Type: Boolean or String of a new index pass or Array of new indexes in preferred ordertrue
Default:
`js`
gulp.task('connect', function() {
connect.server({
root: "app",
middleware: function(connect, opt) {
return [
// ...
]
}
});
});
To contribute to this project, you must have CoffeeScript installed: npm install -g coffee-script.
Then, to build the index.js file, run coffee -o . -bc src/. Run npm test` to run the tests.