-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gulpfile.js
47 lines (41 loc) · 1.31 KB
/
Gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Gulpfile.js
* Task runner with live reload at development mode
*/
var gulp = require("gulp"),
liveReload = require("tiny-lr")(),
app = require("./app");
var LIVERELOADPORT = 35729;
gulp.task("startServer", function () {
app.listen(app.get('port'), function () {
console.log('Express (' + app.get('env') + ') server listening on port ' + app.get('port'));
});
});
gulp.task("startLiveReload", function () {
if (app.get("env") !== "development") {
console.log("Skip live reload for non-dev env");
return;
}
liveReload.listen(LIVERELOADPORT);
});
gulp.task("watchForLiveReload", function () {
if (app.get("env") !== "development") {
console.log("Skip live reload for non-dev env");
return;
}
function trigger (watchedEvent) {
// `gulp.watch()` events provide an absolute path
// so we need to make it relative to the server root
var fileName = require('path').relative(__dirname, watchedEvent.path);
console.log("--- changed --- " + watchedEvent.path + " " + fileName);
liveReload.changed({
body: {
files: [fileName]
}
});
}
gulp.watch("public/index.jade", trigger);
gulp.watch("public/js/task.js", trigger);
gulp.watch("public/css/task.styl", trigger);
});
gulp.task("default", ["startLiveReload", "startServer", "watchForLiveReload"]);