UNPKG

3.55 kBMarkdownView Raw
1gulp-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```
10npm install --save-dev gulp-connect
11```
12
13## Usage
14
15```js
16var gulp = require('gulp'),
17 connect = require('gulp-connect');
18
19gulp.task('connect', function() {
20 connect.server();
21});
22
23gulp.task('default', ['connect']);
24```
25
26#### LiveReload
27```js
28var gulp = require('gulp'),
29 connect = require('gulp-connect');
30
31gulp.task('connect', function() {
32 connect.server({
33 root: 'app',
34 livereload: true
35 });
36});
37
38gulp.task('html', function () {
39 gulp.src('./app/*.html')
40 .pipe(connect.reload());
41});
42
43gulp.task('watch', function () {
44 gulp.watch(['./app/*.html'], ['html']);
45});
46
47gulp.task('default', ['connect', 'watch']);
48```
49
50
51#### Start and stop server
52
53```js
54gulp.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
68var gulp = require('gulp'),
69 stylus = require('gulp-stylus'),
70 connect = require('gulp-connect');
71
72gulp.task('connectDev', function () {
73 connect.server({
74 root: ['app', 'tmp'],
75 port: 8000,
76 livereload: true
77 });
78});
79
80gulp.task('connectDist', function () {
81 connect.server({
82 root: 'dist',
83 port: 8001,
84 livereload: true
85 });
86});
87
88gulp.task('html', function () {
89 gulp.src('./app/*.html')
90 .pipe(connect.reload());
91});
92
93gulp.task('stylus', function () {
94 gulp.src('./app/stylus/*.styl')
95 .pipe(stylus())
96 .pipe(gulp.dest('./app/css'))
97 .pipe(connect.reload());
98});
99
100gulp.task('watch', function () {
101 gulp.watch(['./app/*.html'], ['html']);
102 gulp.watch(['./app/stylus/*.styl'], ['stylus']);
103});
104
105gulp.task('default', ['connectDist', 'connectDev', 'watch']);
106
107```
108
109## API
110
111#### options.root
112
113Type: `Array or String`
114Default: `Directory with gulpfile`
115
116The root path
117
118#### options.port
119
120Type: `Number`
121Default: `8080`
122
123The connect webserver port
124
125#### options.host
126
127Type: `String`
128Default: `localhost`
129
130#### options.https
131
132Type: `Boolean`
133Default: `false`
134
135#### options.livereload
136
137Type: `Object or Boolean`
138Default: `false`
139
140#### options.livereload.port
141
142Type: `Number`
143Default: `35729`
144
145#### options.fallback
146
147Type: `String`
148Default: `undefined`
149
150Fallback file (e.g. `index.html`)
151
152#### options.middleware
153
154Type: `Function`
155Default: `[]`
156
157#### options.debug
158
159Type: `Boolean`
160Default: `false`
161
162
163```js
164gulp.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
178To contribute to this project, you must have CoffeeScript installed: `npm install -g coffee-script`.
179
180Then, 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)