Created
June 3, 2014 05:26
-
-
Save chrisjlee/9b703bfce8dd18ce1c99 to your computer and use it in GitHub Desktop.
express gulp livereload taken from http://rhumaric.com/2014/01/livereload-magic-gulp-style/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require("gulp"); | |
var path = require("path"); | |
var server = { | |
port: 4000, | |
livereloadPort: 35729, | |
basePath: path.join(__dirname, "www"), | |
_lr: null, | |
start: function () { | |
var express = require('express'); | |
var app = express(); | |
app.use(require('connect-livereload')()); | |
app.use(express.static(this.basePath)); | |
app.listen(this.port); | |
}, | |
livereload: function () { | |
this._lr = require('tiny-lr')(); | |
this._lr.listen(this.livereloadPort); | |
}, | |
livestart: function () { | |
this.start(); | |
this.livereload(); | |
}, | |
notify: function (event) { | |
var fileName = path.relative(this.basePath, event.path); | |
this._lr.changed({ | |
body: { | |
files: [fileName] | |
} | |
}); | |
} | |
}; | |
gulp.task("default", function () { | |
server.livestart(); | |
gulp.watch("www/**/*.html", function (event) { | |
server.notify(event); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment