From 2061904276d84c1a53466b93d6fb991c8bff094d Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Tue, 14 Jan 2014 20:53:32 +0200 Subject: [PATCH] add support for livereload --- README.md | 3 +++ gulpfile.coffee | 23 ++++++++++++++++------- package.json | 4 +++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f7348a5..df8917d 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,6 @@ bower install gulp open http://localhost:9001 in your browser + +## Enable LiveReload +Install [LiveReload for Chrome](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei?hl=en) diff --git a/gulpfile.coffee b/gulpfile.coffee index 3063e27..9ca5689 100644 --- a/gulpfile.coffee +++ b/gulpfile.coffee @@ -8,6 +8,10 @@ browserify = require 'gulp-browserify' rename = require 'gulp-rename' uglify = require 'gulp-uglify' coffeeify = require 'coffeeify' +nodeStatic = require 'node-static' +lr = require 'tiny-lr' +livereload = require 'gulp-livereload' +reloadServer = lr() compileCoffee = (debug = false) -> config = transform: ['coffeeify'] @@ -27,12 +31,14 @@ compileCoffee = (debug = false) -> bundle.pipe(uglify()) unless debug bundle.pipe gulp.dest('public/js/') + .pipe livereload reloadServer compileJade = (debug = false) -> gulp .src('src/jade/*.jade') .pipe(jade(pretty: debug)) .pipe(gulp.dest('public/')) + .pipe livereload(reloadServer) compileStylus = (debug = false) -> styles = gulp @@ -42,6 +48,7 @@ compileStylus = (debug = false) -> styles.pipe(CSSmin()) unless debug styles.pipe(gulp.dest('public/css/')) + .pipe livereload reloadServer # Build tasks gulp.task "jade-production", -> compileJade() @@ -54,7 +61,6 @@ gulp.task 'stylus', -> compileStylus(true) gulp.task 'coffee', -> compileCoffee(true) gulp.task "server", -> - nodeStatic = require('node-static') staticFiles = new nodeStatic.Server './public' require('http').createServer (req, res) -> req.addListener 'end', -> @@ -63,14 +69,17 @@ gulp.task "server", -> .listen 9001 gulp.task "watch", -> - gulp.watch "src/coffee/*.coffee", -> - gulp.run "coffee" + reloadServer.listen 35729, (err) -> + console.error err if err? - gulp.watch "src/jade/*.jade", -> - gulp.run "jade" + gulp.watch "src/coffee/*.coffee", -> + gulp.run "coffee" - gulp.watch "src/stylus/*.styl", -> - gulp.run "stylus" + gulp.watch "src/jade/*.jade", -> + gulp.run "jade" + + gulp.watch "src/stylus/*.styl", -> + gulp.run "stylus" gulp.task "build", -> gulp.run "coffee-production", "jade-production", "stylus-production" diff --git a/package.json b/package.json index a697961..45ac71f 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "gulp": "~3.3.1", "node-static": "~0.7.3", "gulp-minify-css": "~0.2.0", - "coffeeify": "~0.5.2" + "coffeeify": "~0.5.2", + "tiny-lr": "0.0.5", + "gulp-livereload": "~0.2.0" } }