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
32 lines (25 loc) · 973 Bytes
/
livereload.js
File metadata and controls
32 lines (25 loc) · 973 Bytes
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
let livereloadServer = require('engine/livereloadServer')
let chokidar = require('chokidar');
// options.watch must NOT be www/**, because that breaks (why?!?) supervisor reloading
// www/**/*.* is fine
module.exports = async function(options) {
function onChokidarChange(changed) {
changed = changed.slice(options.base.length + 1);
// console.log("CHANGE", changed);
if (!changed.match(/\.(jpg|css|png|gif|svg)/i)) {
changed = '/fullpage'; // make all requests that cause full-page reload be /fullpage
// otherwise we'll have many reloads (once per diffrent .js url)
}
livereloadServer.queueFlush(changed);
}
setTimeout(function() {
// console.log("livereload: listen on change " + options.watch);
chokidar.watch(options.watch, {
awaitWriteFinish: {
stabilityThreshold: 300,
pollInterval: 100
}
}).on('change', onChokidarChange);
}, 1000);
await new Promise(resolve => {});
};