Add LiveReload (#663)

This commit is contained in:
Amy Lam 2018-05-17 16:17:56 -07:00 committed by Joel Marcey
parent fed67dcee4
commit f9a09072e3
8 changed files with 279 additions and 9 deletions

View file

@ -21,6 +21,10 @@ function execute(port) {
const mkdirp = require('mkdirp');
const glob = require('glob');
const chalk = require('chalk');
const gaze = require('gaze');
const tinylr = require('tiny-lr');
const constants = require('../core/constants');
const translate = require('./translate');
const {renderToStaticMarkupWithDoctype} = require('./renderUtils');
@ -541,6 +545,33 @@ function execute(port) {
);
});
// Start LiveReload server.
process.env.NODE_ENV = 'development';
const server = tinylr();
server.listen(constants.LIVE_RELOAD_PORT, function() {
console.log(
'LiveReload server started on port %d',
constants.LIVE_RELOAD_PORT
);
});
// gaze watches some specified dirs and triggers a callback when they change.
gaze(
[
'../docs/**/*', // docs
'**/*', // website
],
function() {
// Listen for all kinds of file changes - modified/added/deleted.
this.on('all', function() {
// Notify LiveReload clients that there's a change.
// Typically, LiveReload will only refresh the changed paths,
// so we use / here to force a full-page reload.
server.notifyClients(['/']);
});
}
);
app.listen(port);
}