forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlivereload.js
More file actions
executable file
·41 lines (33 loc) · 1.19 KB
/
livereload.js
File metadata and controls
executable file
·41 lines (33 loc) · 1.19 KB
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
var livereload = require('gulp-livereload');
var gulp = require('gulp');
var gutil = require('gulp-util');
var throttle = require('lodash/throttle');
var chokidar = require('chokidar');
// options.watch must NOT be www/**, because that breaks (why?!?) supervisor reloading
// www/**/*.* is fine
module.exports = function(options) {
// listen to changes after the file events finish to arrive
// no one is going to livereload right now anyway
return function(callback) {
livereload.listen();
// reload once after all scripts are rebuit
livereload.changedSoon = throttle(livereload.changed, 1000, {leading: false});
//livereload.changedVerySoon = _.throttle(livereload.changed, 100, {leading: false});
setTimeout(function() {
gutil.log("livereload: listen on change " + options.watch);
chokidar.watch(options.watch, {
awaitWriteFinish: {
stabilityThreshold: 300,
pollInterval: 100
}
}).on('change', function(changed) {
if (changed.match(/\.(js|map)/)) {
// full page reload
livereload.changedSoon(changed);
} else {
livereload.changed(changed);
}
});
}, 1000);
};
};