gulp-live-server
A handy, light-weight server you're going to love.
Install
Usage
-
Serve a static folder(
gls.script
<'scripts/static.js'> is used as server script)var gulp = ;var gls = ;gulp; -
Serve with your own script file
gulp; -
Customized serving with gls
gulp;
API
static([folder][, port])
folder
-String|Array
The folder(s) to serve. Use array of strings if there're multi folders to serve. If omitted, defaults topublic/
.port
-Number
The port to listen on. Defaults to3000
.- return gls.
Config new server using the default server script, to serve the given folder
on the specified port
.
new(script)
script
-String
The script file to run.- return gls.
Config new server using the given script
.
gls(args[, options][, livereload])
-
args
-String|Array
The 2nd param for ChildProcess.spawn. -
options
-Object
The 3rd param for ChildProcess.spawn, will be mixin into the default value:options =cwd: undefinedoptionsenv = processenv;optionsenvNODE_ENV = 'development'; -
livereload
-Boolean|Number|Object
The option for tiny-lr server. The default value is35729
.false
- will disable tiny-lr livereload server.number
- treated as port number of livereload server.object
- used to create tiny-lr server new tinylr.Server(livereload);
gls
here is a reference of var gls = require('gulp-live-server')
. It aims to assemble configuration for the server child process as well as the tiny-lr server.
static
and new
are just shortcuts for this.
Usually, static
and new
will serve you well, but you can get more customized server with gls
.
start([execPath])
execPath
-String
The executable that is used to start the server. If none is given the current node executable is used.- return promise from Q, resolved with the server process exits.
Spawn a new child process based on the configuration.
- use
ChildProcess.spawn
to start a node process; - use
tiny-lr
provide livereload ability;
stop()
Stop the server.
notify([event])
event
-Event
Event object passed along with gulp.watch. Optional when used withpipe
.
Tell livereload.js to reload the changed resource(s)
livereload.js
gulp-live-server comes with tiny-lr built in, which works as a livereload server. livereload.js
is served by tiny-lr
, but in order to get it loaded with your page, you have 3 options( to inject <script src="//localhost:35729/livereload.js"></script>
into your page):
- LiveReload for Chrome;
- Use connect-livereload middleware;
- Add livereload.js in your page manually;
Usually, if http://localhost:35729/livereload.js
is accessible, then your livereload server is ok, if you don't have the script tag for livereload.js in you page, you've problem with either your chrome plugin or the connect-livereload middle-ware as mentioned above.
DEBUG
If you want more output, set the DEBUG
environment variables to *
or gulp-live-server
.