• Stars
    star
    356
  • Rank 119,446 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Streaming gulp plugin to run a local webserver with LiveReload

gulp-webserver Build Status

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

Key Type Default Description
host String localhost hostname of the webserver
port Number 8000 port of the webserver
path String / path to the webserver
livereload Boolean/Object false whether 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.
directoryListing Boolean/Object false whether 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.
fallback String undefined file to fall back to (relative to webserver root)
open Boolean/String false open 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/) .
https Boolean/Object false whether 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'}.
middleware Function/Array [] a connect middleware function or a list of middleware functions
proxies Array [] 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

More Repositories

1

chromeless

🖥 Chrome automation made simple. Runs locally or headless on AWS Lambda.
TypeScript
13,240
star
2

dockerfiles

Collection of lightweight and ready-to-use docker images
Shell
835
star
3

laravel-backup

Backup and restore database support for Laravel 4 applications
PHP
351
star
4

docker-hook

Automatic Docker Deployment via Webhooks
Python
257
star
5

git-s3

Easy way to deploy your git repo to an AWS S3 bucket
PHP
228
star
6

Device.swift

Super-lightweight library to detect used device
Swift
220
star
7

timemachine

Test your time-dependent app by monkey patching the Date function and overriding your system time.
JavaScript
133
star
8

calculate-size

Calculate the pixel size (width/height) of a string (with integrated caching)
TypeScript
121
star
9

awesome-local-first

A collection of awesome local-first projects including offline-first and collaboration functionality
93
star
10

beanstalkd-cli

Simple to use commandline tool for Beanstalkd
Rust
71
star
11

dotfiles

Contents of my ~/.config
Nix
63
star
12

rust-beanstalkd

Easy-to-use beanstalkd client for Rust (IronMQ compatible)
Rust
46
star
13

vim-bufonly

Delete all the buffers except the current buffer.
Vim Script
40
star
14

laravel-cash

Simple to use cache layer for your laravel application using memcached & nginx.
PHP
34
star
15

three-vr

Device controls and render steps for mobile virtual reality applications
JavaScript
30
star
16

laravel-queue-checker

Command to check the queue health status
PHP
26
star
17

Icomoon.swift

Use your Icomoon fonts with Swift - auto-generates type safe enums for each icon
Swift
26
star
18

fps-meter

TypeScript
18
star
19

gulp-webserver-article

Code examples for "Gulp as a (development) webserver"
JavaScript
17
star
20

colorrado

Beautiful color gradients based on images
TypeScript
15
star
21

local-first-landscape

A resource to learn about and compare tools in the local-first landscape
11
star
22

rust-examples

Rust examples in order to learn the language
Rust
11
star
23

zipcoder

Get zipcode, city and country for given coordinates or user location
JavaScript
11
star
24

jquery-rotate

Very lightweight jquery rotate plugin using CSS 3 Transformation
JavaScript
11
star
25

figma-plugin-code-syntax-highlighting

TypeScript
11
star
26

immersive

Virtual room tour using Google Cardboard
JavaScript
8
star
27

opentelemetry

8
star
28

algorithms

Implementation of several algorithms in Javascript
JavaScript
8
star
29

coroni

🦠
TypeScript
8
star
30

laravel-validators

A set of additional validator rules for Laravel 4
PHP
7
star
31

crawl-notifier

Crawl any website and get notified via mail when changes occur
JavaScript
5
star
32

graphql-summit-demo

TypeScript
4
star
33

react-figma-tailwind

JavaScript
4
star
34

dunkelziffer

News crawler for the deep web
JavaScript
4
star
35

crud-codegen

TypeScript
3
star
36

challenges

Coding challenges - talk about solutions
Python
3
star
37

graphql-delegate-subscriptions-example

TypeScript
3
star
38

angular-coordinate

Coordiante system for AngularJS
JavaScript
3
star
39

laravel-schema-summary

Creates a summary file of all migrations
2
star
40

es-producthunt

TypeScript
2
star
41

hackrisk-calm-app

iPhone + Apple Watch App to detect and avoid stressful situations
Swift
2
star
42

base-konfik

Base configuration files for Konfik
TypeScript
2
star
43

contentlayer-blog-2

Jamstack site created with Stackbit
TypeScript
1
star
44

relay-compiler-bug

Minimal reproduction of the recursive input type bug in relay-compiler
JavaScript
1
star
45

codenames

Codenames Game built as React-Native app
JavaScript
1
star
46

slides

Slides for my talks
JavaScript
1
star