JSPM

  • Created
  • Published
  • Downloads 10639
  • Score
    100M100P100Q134076F
  • License WTFPL

easy light weight server with livereload

Package Exports

  • gulp-live-server

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-live-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gulp-live-server

status downloads tag license

A handy, light-weight server you're going to love.

Install

NPM

Usage

  • serve a static folder

    var gulp = require('gulp');
    var gls = require('gulp-live-server');
    gulp.task('serve', function() {
        var server = gls.static();
        server.start();
        //live reload changed resource(s)
        gulp.watch(['static/**/*.css', 'static/**/*.html'], server.notify);
    });
  • fire up your own server

    gulp.task('serve', function() {
        var server = gls.new('myapp.js');
        server.start();
        gulp.watch(['static/**/*.css', 'static/**/*.html'], server.notify);
        //restart my server
        gulp.watch('myapp.js', server.start);
    });

More examples

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 to public/.
  • port - Number The port to listen on. Defaults to 3000.
  • 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: undefined
        }
        options.env = process.env;
        options.env.NODE_ENV = 'development';
  • livereload - Boolean|Number|Object The option for tiny-lr server. The default value is 35729.

    • 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()

Spawn a new child process based on the configuration.

stop()

Stop the server.

notify([event])

  • event - Event Event object passed along with gulp.watch. Optional when used with pipe.

Tell livereload.js to reload the changed resource(s)

livereload.js

glup-live-server comes with tiny-lr built in, which works as a livereload server, In order to make livereload work with your pages, you still need livereload.js loaded with your page, there're 3 options to achieve this:

Usually, you can check http://livereload:35729/livereload.js to see if livereload.js is loaded with your page.

DEBUG

If you want more output, set the DEBUG environment variables to * or gulp-live-server.