Skip to content

Commit 2b69d89

Browse files
committed
minor fixes
1 parent bf1d7ad commit 2b69d89

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

edit

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
: ${1?"Usage: $0 <tutorial language> [<server language>]"}
77

88

9-
export TUTORIAL_ROOT="../$1.javascript.info"
9+
if [ -z "$TUTORIAL_ROOT" ]; then
10+
export TUTORIAL_ROOT="../$1.javascript.info"
11+
fi
1012
export NODE_LANG="${2:-en}"
1113
export TUTORIAL_LANG=$1
1214
export NODE_ENV=production

gulpfile.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ task("nodemon", lazyRequireTask('./tasks/nodemon', {
3030
watch: ["modules"]
3131
}));
3232

33-
task("livereload", lazyRequireTask("./tasks/livereload", {
33+
task('livereload', lazyRequireTask('./tasks/livereload', {
3434
// watch files *.*, not directories, no need to reload for new/removed files,
3535
// we're only interested in changes
3636

37+
base: `public/${config.lang}`,
3738
watch: [
38-
"public/pack/**/*.*",
39+
`public/${config.lang}/pack/**/*.*`,
40+
// not using this file, using only styles.css (extracttextplugin)
41+
`!public/${config.lang}/pack/styles.js`,
3942
// this file changes every time we update styles
4043
// don't watch it, so that the page won't reload fully on style change
41-
"!public/pack/head.js"
44+
`!public/${config.lang}/pack/head.js`
4245
]
4346
}));
4447

tasks/livereload.js

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
1-
let livereload = require('gulp-livereload');
2-
let gulp = require('gulp');
3-
let throttle = require('lodash/throttle');
1+
let livereloadServer = require('engine/livereloadServer')
42
let chokidar = require('chokidar');
53

64
// options.watch must NOT be www/**, because that breaks (why?!?) supervisor reloading
75
// www/**/*.* is fine
86
module.exports = async function(options) {
97

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);
1311

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+
}
1718

1819
setTimeout(function() {
19-
console.log("livereload: listen on change " + options.watch);
20+
// console.log("livereload: listen on change " + options.watch);
2021

2122
chokidar.watch(options.watch, {
2223
awaitWriteFinish: {
2324
stabilityThreshold: 300,
24-
pollInterval: 100
25+
pollInterval: 100
2526
}
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);
3428

3529
}, 1000);
3630

3731
await new Promise(resolve => {});
3832
};
39-
40-

0 commit comments

Comments
 (0)