Last active
January 1, 2016 00:29
-
-
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…
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 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] | |
} | |
}); | |
}); | |
}); |
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
{ | |
"name": "site", | |
"dependencies": { | |
"tiny-lr": "0.0.5", | |
"gulp": "~3.2.0", | |
"express": "~3.4.7", | |
"gulp-util": "~2.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another, more dynamic, solution https://gist.github.com/kevva/8548035.