mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 11:47:23 +02:00
Add option to disable live reload server during development (#766)
* add option to disable live reload server * change live to watch, fix incorrect argument parsing code * Update api-commands.md
This commit is contained in:
parent
608e2c85a2
commit
62a2c7c1a5
3 changed files with 38 additions and 31 deletions
|
@ -145,6 +145,7 @@ This script will build the static website, apply translations if necessary, and
|
|||
| Options | Default | Description |
|
||||
| ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `--port <number>` | `3000` | The website will be served from port 3000 by default, but if the port is taken up, Docusaurus will attempt to find an available one. |
|
||||
| `--watch` | - | Whether to watch the files and live reload the page when files are changed. Defaults to true. Disable this by using `--no-watch`. |
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
function execute(port) {
|
||||
function execute(port, options) {
|
||||
const extractTranslations = require('../write-translations');
|
||||
|
||||
const metadataUtils = require('./metadataUtils');
|
||||
|
@ -568,6 +568,10 @@ function execute(port) {
|
|||
});
|
||||
});
|
||||
|
||||
if (options.watch) startLiveReload();
|
||||
app.listen(port);
|
||||
|
||||
function startLiveReload() {
|
||||
// Start LiveReload server.
|
||||
process.env.NODE_ENV = 'development';
|
||||
const server = tinylr();
|
||||
|
@ -595,8 +599,7 @@ function execute(port) {
|
|||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.listen(port);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = execute;
|
||||
|
|
|
@ -42,7 +42,10 @@ if (env.versioning.enabled && env.versioning.missingVersionsPage) {
|
|||
|
||||
const program = require('commander');
|
||||
|
||||
program.option('--port <number>', 'Specify port number').parse(process.argv);
|
||||
program
|
||||
.option('--port <number>', 'Specify port number')
|
||||
.option('--no-watch', 'Toggle live reload file watching')
|
||||
.parse(process.argv);
|
||||
|
||||
let port = parseInt(program.port, 10) || process.env.PORT || 3000;
|
||||
let numAttempts = 0;
|
||||
|
@ -68,7 +71,7 @@ function checkPort() {
|
|||
} else {
|
||||
// start local server on specified port
|
||||
const server = require('./server/server.js');
|
||||
server(port);
|
||||
server(port, program.opts());
|
||||
const host = `http://localhost:${port}`;
|
||||
console.log('Docusaurus server started on port %d', port);
|
||||
openBrowser(host);
|
||||
|
|
Loading…
Add table
Reference in a new issue