Skip to content

Instantly share code, notes, and snippets.

@yocontra
Last active January 1, 2016 00:29
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save yocontra/8066801 to your computer and use it in GitHub Desktop.
Save yocontra/8066801 to your computer and use it in GitHub Desktop.
gulpfile for a simple livereload static web server. this is a proof of concept that uses no plugins to do the work. obviously there are plugins that eliminate almost all of this code but i thought it would be a fun demonstration. this will trigger livereload any time any file is modified in the current working directory. it also serves the curre…
var gulp = require('gulp');
var gutil = require('gulp-util');
var express = require('express');
var path = require('path');
var tinylr = require('tiny-lr');
var createServers = function(port, lrport) {
var lr = tinylr();
lr.listen(lrport, function() {
gutil.log('LR Listening on', lrport);
});
var app = express();
app.use(express.static(path.resolve('./')));
app.listen(port, function() {
gutil.log('Listening on', port);
});
return {
lr: lr,
app: app
};
};
var servers = createServers(8080, 35729);
gulp.task('default', function(){
gulp.watch(["./**/*", "!./node_modules/**/*"], function(evt){
gutil.log(gutil.colors.cyan(evt.path), 'changed');
servers.lr.changed({
body: {
files: [evt.path]
}
});
});
});
{
"name": "site",
"dependencies": {
"tiny-lr": "0.0.5",
"gulp": "~3.2.0",
"express": "~3.4.7",
"gulp-util": "~2.2.0"
}
}
@kevva
Copy link

kevva commented Jan 21, 2014

Another, more dynamic, solution https://gist.github.com/kevva/8548035.

@tsq
Copy link

tsq commented Mar 17, 2015

Very good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment