1 | gulp-connect [![Build Status](http://img.shields.io/travis/AveVlad/gulp-connect.svg?style=flat-square)](https://travis-ci.org/AveVlad/gulp-connect) [![](http://img.shields.io/npm/dm/gulp-connect.svg?style=flat-square)](https://www.npmjs.org/package/gulp-connect) [![](http://img.shields.io/npm/v/gulp-connect.svg?style=flat-square)](https://www.npmjs.org/package/gulp-connect) [![Join the chat at https://gitter.im/AveVlad/gulp-connect](https://badges.gitter.im/AveVlad/gulp-connect.svg)](https://gitter.im/AveVlad/gulp-connect?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
2 | ==============
|
3 |
|
4 | > Gulp plugin to run a webserver (with LiveReload)
|
5 |
|
6 |
|
7 | ## Install
|
8 |
|
9 | ```
|
10 | npm install --save-dev gulp-connect
|
11 | ```
|
12 |
|
13 | ## Usage
|
14 |
|
15 | ```js
|
16 | var gulp = require('gulp'),
|
17 | connect = require('gulp-connect');
|
18 |
|
19 | gulp.task('connect', function() {
|
20 | connect.server();
|
21 | });
|
22 |
|
23 | gulp.task('default', ['connect']);
|
24 | ```
|
25 |
|
26 | #### LiveReload
|
27 | ```js
|
28 | var gulp = require('gulp'),
|
29 | connect = require('gulp-connect');
|
30 |
|
31 | gulp.task('connect', function() {
|
32 | connect.server({
|
33 | root: 'app',
|
34 | livereload: true
|
35 | });
|
36 | });
|
37 |
|
38 | gulp.task('html', function () {
|
39 | gulp.src('./app/*.html')
|
40 | .pipe(connect.reload());
|
41 | });
|
42 |
|
43 | gulp.task('watch', function () {
|
44 | gulp.watch(['./app/*.html'], ['html']);
|
45 | });
|
46 |
|
47 | gulp.task('default', ['connect', 'watch']);
|
48 | ```
|
49 |
|
50 |
|
51 | #### Start and stop server
|
52 |
|
53 | ```js
|
54 | gulp.task('jenkins-tests', function() {
|
55 | connect.server({
|
56 | port: 8888
|
57 | });
|
58 | // run some headless tests with phantomjs
|
59 | // when process exits:
|
60 | connect.serverClose();
|
61 | });
|
62 | ```
|
63 |
|
64 |
|
65 | #### Multiple server
|
66 |
|
67 | ```js
|
68 | var gulp = require('gulp'),
|
69 | stylus = require('gulp-stylus'),
|
70 | connect = require('gulp-connect');
|
71 |
|
72 | gulp.task('connectDev', function () {
|
73 | connect.server({
|
74 | root: ['app', 'tmp'],
|
75 | port: 8000,
|
76 | livereload: true
|
77 | });
|
78 | });
|
79 |
|
80 | gulp.task('connectDist', function () {
|
81 | connect.server({
|
82 | root: 'dist',
|
83 | port: 8001,
|
84 | livereload: true
|
85 | });
|
86 | });
|
87 |
|
88 | gulp.task('html', function () {
|
89 | gulp.src('./app/*.html')
|
90 | .pipe(connect.reload());
|
91 | });
|
92 |
|
93 | gulp.task('stylus', function () {
|
94 | gulp.src('./app/stylus/*.styl')
|
95 | .pipe(stylus())
|
96 | .pipe(gulp.dest('./app/css'))
|
97 | .pipe(connect.reload());
|
98 | });
|
99 |
|
100 | gulp.task('watch', function () {
|
101 | gulp.watch(['./app/*.html'], ['html']);
|
102 | gulp.watch(['./app/stylus/*.styl'], ['stylus']);
|
103 | });
|
104 |
|
105 | gulp.task('default', ['connectDist', 'connectDev', 'watch']);
|
106 |
|
107 | ```
|
108 |
|
109 | ## API
|
110 |
|
111 | #### options.root
|
112 |
|
113 | Type: `Array or String`
|
114 | Default: `Directory with gulpfile`
|
115 |
|
116 | The root path
|
117 |
|
118 | #### options.port
|
119 |
|
120 | Type: `Number`
|
121 | Default: `8080`
|
122 |
|
123 | The connect webserver port
|
124 |
|
125 | #### options.host
|
126 |
|
127 | Type: `String`
|
128 | Default: `localhost`
|
129 |
|
130 | #### options.https
|
131 |
|
132 | Type: `Boolean`
|
133 | Default: `false`
|
134 |
|
135 | #### options.livereload
|
136 |
|
137 | Type: `Object or Boolean`
|
138 | Default: `false`
|
139 |
|
140 | #### options.livereload.port
|
141 |
|
142 | Type: `Number`
|
143 | Default: `35729`
|
144 |
|
145 | #### options.fallback
|
146 |
|
147 | Type: `String`
|
148 | Default: `undefined`
|
149 |
|
150 | Fallback file (e.g. `index.html`)
|
151 |
|
152 | #### options.middleware
|
153 |
|
154 | Type: `Function`
|
155 | Default: `[]`
|
156 |
|
157 | #### options.debug
|
158 |
|
159 | Type: `Boolean`
|
160 | Default: `false`
|
161 |
|
162 |
|
163 | ```js
|
164 | gulp.task('connect', function() {
|
165 | connect.server({
|
166 | root: "app",
|
167 | middleware: function(connect, opt) {
|
168 | return [
|
169 | // ...
|
170 | ]
|
171 | }
|
172 | });
|
173 | });
|
174 | ```
|
175 |
|
176 | ## Contributing
|
177 |
|
178 | To contribute to this project, you must have CoffeeScript installed: `npm install -g coffee-script`.
|
179 |
|
180 | Then, to build the `index.js` file, run `coffee -o . -bc src/`. Run `npm test` to run the tests.
|
181 |
|
182 | ## Contributors
|
183 |
|
184 | * [AveVlad](https://github.com/AveVlad)
|
185 | * [schickling](https://github.com/schickling)
|
186 | * [justinmchase](https://github.com/justinmchase)
|