Skip to content

standy/gulp-express

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-express

Livereload downloads MIT Licensed

A simple gulp plugin which:

Update notice

  • v0.1.12

    options.lr is used for creating tiny-lr server. options here is the second parameter for server.run.

  • v0.1.7

    change signature for server.run, split options into args and options.

  • v0.1.5

    pipe support added for server.notify

Install

$ npm install --save-dev gulp-express

API

server.run([args][,options])

Run or re-run the script file, which will create a server. Use the same arguments with ChildProcess.spawn with 'node' as command.

  • args - Array - Array List of string arguments. The default value is ['app.js'].
  • options - Object - The third parameter for ChildProcess.spawn, the default value is:
options = {
    cwd: undefined,
    lr: {//lr will be used for tiny-lr server construction
        port: 35729
    }
}
options.env = process.env;
options.env.NODE_ENV = 'development';

server.stop()

Stop the instantiated spawned server programmatically, and the tiny-lr server.

server.notify([event])

Send a notification to the tiny-lr server in order to trigger a reload on page. pipe support is added after v0.1.5, so you can also do this:

gulp.src('css/*.css')
// …
.pipe(gulp.dest('public/css/'))
.pipe(server.notify())
  • event (required when server.notify is invoked without pipe) - Object - Event object that is normally passed to gulp.watch callback. Should contain path property with changed file path.

Usage

// gulpfile.js
var gulp = require('gulp');
var server = require('gulp-express');

gulp.task('server', function () {
    // Start the server at the beginning of the task
    server.run(['app.js']);

    // Restart the server when file changes
    gulp.watch(['app/**/*.html'], server.notify);
    gulp.watch(['app/styles/**/*.scss'], ['styles:scss']);
    //gulp.watch(['{.tmp,app}/styles/**/*.css'], ['styles:css', server.notify]);
    //Event object won't pass down to gulp.watch's callback if there's more than one of them.
    //So the correct way to use server.notify is as following:
    gulp.watch(['{.tmp,app}/styles/**/*.css'], function(event){
        gulp.run('styles:css');
        server.notify(event);
        //pipe support is added for server.notify since v0.1.5,
        //see https://github.com/gimm/gulp-express#servernotifyevent
    });

    gulp.watch(['app/scripts/**/*.js'], ['jshint']);
    gulp.watch(['app/images/**/*'], server.notify);
    gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
});
// app.js
var express = require('express');
var app = module.exports.app = exports.app = express();

//you won't need 'connect-livereload' if you have livereload plugin for your browser
app.use(require('connect-livereload')());

About

gulp plugin for express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%