mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
Add LiveReload (#663)
This commit is contained in:
parent
fed67dcee4
commit
f9a09072e3
8 changed files with 279 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue