gulp-connect
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/gulp-connect package

5.7.0 • Public • Published

gulp-connect Build Status Join the chat at https://gitter.im/AveVlad/gulp-connect

Gulp plugin to run a webserver (with LiveReload)

Sponsors

gulp-connect is sponsored by JetBrains!

Install

npm install --save-dev gulp-connect

Usage

var gulp = require('gulp'),
  connect = require('gulp-connect');
 
gulp.task('connect', function() {
  connect.server();
});
 
gulp.task('default', ['connect']);

LiveReload

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

gulp.task('jenkins-tests', function() {
  connect.server({
    port: 8888
  });
  // run some headless tests with phantomjs
  // when process exits:
  connect.serverClose();
});

Multiple server

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.

API

options.root

Type: Array or String Default: Directory with gulpfile

The root path

options.port

Type: Number Default: 8080

The connect webserver port

options.host

Type: String Default: localhost

options.name

Type: String Default: Server

The name that will be output when the server starts/stops.

options.https

Type: Object Default: false

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 Boolean Default: false

options.livereload.port

Type: Number Default: 35729

Overrides the hostname of the script livereload injects in index.html

options.livereload.hostname

Type: String Default: 'undefined'

options.fallback

Type: String Default: undefined

Fallback file (e.g. index.html)

options.middleware

Type: Function Default: []

options.debug

Type: Boolean Default: false

options.index

Type: Boolean or String of a new index pass or Array of new indexes in preferred order Default: true

gulp.task('connect', function() {
  connect.server({
    root: "app",
    middleware: function(connect, opt) {
      return [
        // ...
      ]
    }
  });
});

Contributing

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.

Contributors

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
5.7.049,908latest

Version History

VersionDownloads (Last 7 Days)Published
5.7.049,908
5.6.1312
5.5.02,156
5.4.02
5.2.028
5.1.03
5.0.0980
4.2.0353
4.1.04
4.0.072
3.2.3211
3.2.24
3.2.12
3.2.01
3.1.11
3.1.08
3.0.01
2.3.12,929
2.3.01
2.2.0297
2.1.04
2.0.680
2.0.515
2.0.45
2.0.31
2.0.22
2.0.12
2.0.01
1.1.12
1.1.03
1.0.102
1.0.91
1.0.73
1.0.62
1.0.51
1.0.42
1.0.31
1.0.22
1.0.11
1.0.01
0.9.01
0.8.02
0.7.02
0.6.01
0.5.01
0.4.02
0.3.11
0.3.01
0.2.04
0.1.61
0.1.52
0.1.44
0.1.32
0.1.21
0.1.12
0.0.11

Package Sidebar

Install

npm i gulp-connect

Weekly Downloads

57,432

Version

5.7.0

License

MIT

Unpacked Size

199 kB

Total Files

15

Last publish

Collaborators

  • avevlad
  • justinmchase