From 852b5e8f13dacb58c9ee4aadd30e27313be9a232 Mon Sep 17 00:00:00 2001 From: Tom Brien Date: Mon, 20 Apr 2020 03:49:43 +0100 Subject: [PATCH] feat(v2): add CLI option for polling (#2630) * Add CLI option to polling Some environments (specifically docker containers) can have issues with file watching for live reloads. [Webpack Dev Server provides a polling alternative](https://webpack.js.org/configuration/watch/#watchoptionspoll) option for this * Update docusaurus.js * Update cli.md Co-authored-by: Yangshun Tay --- packages/docusaurus-types/src/index.d.ts | 1 + packages/docusaurus/bin/docusaurus.js | 7 ++++++- packages/docusaurus/src/commands/start.ts | 1 + website/docs/cli.md | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 2dbdc89b1c..4c2c1cea0f 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -60,6 +60,7 @@ export interface StartCLIOptions { host: string; hotOnly: boolean; open: boolean; + poll: boolean; } export interface BuildCLIOptions { diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index 6ccc8e20d7..22bac22067 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -85,12 +85,17 @@ cli 'Do not fallback to page refresh if hot reload fails (default: false)', ) .option('--no-open', 'Do not open page in the browser (default: false)') - .action((siteDir = '.', {port, host, hotOnly, open}) => { + .option( + '--poll', + 'Use polling rather than watching for reload (default: false)', + ) + .action((siteDir = '.', {port, host, hotOnly, open, poll}) => { wrapCommand(start)(path.resolve(siteDir), { port, host, hotOnly, open, + poll, }); }); diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 25d5f89df2..04ee554fe1 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -141,6 +141,7 @@ export async function start( publicPath: baseUrl, watchOptions: { ignored: /node_modules/, + poll: cliOptions.poll, }, historyApiFallback: { rewrites: [{from: /\/*/, to: baseUrl}], diff --git a/website/docs/cli.md b/website/docs/cli.md index 36c8f9a283..0495a67f99 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -48,6 +48,7 @@ Builds and serves a preview of your site locally with [Webpack Dev Server](https | `--host` | `localhost` | Specify a host to use. E.g., if you want your server to be accessible externally, you can use `--host 0.0.0.0` | | `--hot-only` | `false` | Enables Hot Module Replacement without page refresh as fallback in case of build failures. More information [here](https://webpack.js.org/configuration/dev-server/#devserverhotonly). | | `--no-open` | `false` | Do not open automatically the page in the browser. | +| `--poll` | `false` | Use polling of files rather than watching for live reload as a fallback in environments where watching doesn't work. More information [here](https://webpack.js.org/configuration/watch/#watchoptionspoll). | :::important