|
1 |
| -let livereload = require('gulp-livereload'); |
2 |
| -let gulp = require('gulp'); |
3 |
| -let throttle = require('lodash/throttle'); |
| 1 | +let livereloadServer = require('engine/livereloadServer') |
4 | 2 | let chokidar = require('chokidar');
|
5 | 3 |
|
6 | 4 | // options.watch must NOT be www/**, because that breaks (why?!?) supervisor reloading
|
7 | 5 | // www/**/*.* is fine
|
8 | 6 | module.exports = async function(options) {
|
9 | 7 |
|
10 |
| - // listen to changes after the file events finish to arrive |
11 |
| - // no one is going to livereload right now anyway |
12 |
| - livereload.listen(); |
| 8 | + function onChokidarChange(changed) { |
| 9 | + changed = changed.slice(options.base.length + 1); |
| 10 | + // console.log("CHANGE", changed); |
13 | 11 |
|
14 |
| - // reload once after all scripts are rebuit |
15 |
| - livereload.changedSoon = throttle(livereload.changed, 1000, {leading: false}); |
16 |
| - //livereload.changedVerySoon = _.throttle(livereload.changed, 100, {leading: false}); |
| 12 | + if (!changed.match(/\.(jpg|css|png|gif|svg)/i)) { |
| 13 | + changed = '/fullpage'; // make all requests that cause full-page reload be /fullpage |
| 14 | + // otherwise we'll have many reloads (once per diffrent .js url) |
| 15 | + } |
| 16 | + livereloadServer.queueFlush(changed); |
| 17 | + } |
17 | 18 |
|
18 | 19 | setTimeout(function() {
|
19 |
| - console.log("livereload: listen on change " + options.watch); |
| 20 | + // console.log("livereload: listen on change " + options.watch); |
20 | 21 |
|
21 | 22 | chokidar.watch(options.watch, {
|
22 | 23 | awaitWriteFinish: {
|
23 | 24 | stabilityThreshold: 300,
|
24 |
| - pollInterval: 100 |
| 25 | + pollInterval: 100 |
25 | 26 | }
|
26 |
| - }).on('change', function(changed) { |
27 |
| - if (changed.match(/\.(js|map)/)) { |
28 |
| - // full page reload |
29 |
| - livereload.changedSoon(changed); |
30 |
| - } else { |
31 |
| - livereload.changed(changed); |
32 |
| - } |
33 |
| - }); |
| 27 | + }).on('change', onChokidarChange); |
34 | 28 |
|
35 | 29 | }, 1000);
|
36 | 30 |
|
37 | 31 | await new Promise(resolve => {});
|
38 | 32 | };
|
39 |
| - |
40 |
| - |
0 commit comments