diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index d625e4d110ae..a1a33461e27d 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -101,7 +101,7 @@ export type HostPortCLIOptions = { export type StartCLIOptions = HostPortCLIOptions & { hotOnly: boolean; open: boolean; - poll: boolean; + poll: boolean | number; }; export type ServeCLIOptions = HostPortCLIOptions & { diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index ec3f39594a17..0603dbcfc5eb 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -146,8 +146,8 @@ cli ) .option('--no-open', 'Do not open page in the browser (default: false)') .option( - '--poll', - 'Use polling rather than watching for reload (default: false)', + '--poll [interval]', + 'Use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds.', ) .action((siteDir = '.', {port, host, hotOnly, open, poll}) => { wrapCommand(start)(path.resolve(siteDir), { diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 673fd1bb725d..5586f698ea0f 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -81,10 +81,16 @@ export default async function start( .filter(Boolean), ) .map(normalizeToSiteDir); + const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], { cwd: siteDir, ignoreInitial: true, + usePolling: !!cliOptions.poll, + interval: Number.isInteger(cliOptions.poll) + ? (cliOptions.poll as number) + : undefined, }); + ['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload), ); diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap index f842a100afe6..f034064be813 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap @@ -6,7 +6,7 @@ exports[`loadConfig website with incomplete siteConfig 1`] = ` " `; -exports[`loadConfig website with no siteConfig 1`] = `"docusaurus.config.js not found"`; +exports[`loadConfig website with no siteConfig 1`] = `"docusaurus.config.js not found at packages/docusaurus/src/server/__tests__/__fixtures__/nonExisting/docusaurus.config.js"`; exports[`loadConfig website with useless field (wrong field) in siteConfig 1`] = ` "\\"favicon\\" is required diff --git a/packages/docusaurus/src/server/config.ts b/packages/docusaurus/src/server/config.ts index 6891ad0c3975..ffecdcd1b781 100644 --- a/packages/docusaurus/src/server/config.ts +++ b/packages/docusaurus/src/server/config.ts @@ -20,7 +20,12 @@ export default function loadConfig(siteDir: string): DocusaurusConfig { const configPath = path.resolve(siteDir, loadedConfigFileName); if (!fs.existsSync(configPath)) { - throw new Error(`${CONFIG_FILE_NAME} not found`); + throw new Error( + `${CONFIG_FILE_NAME} not found at ${path.relative( + process.cwd(), + configPath, + )}`, + ); } const loadedConfig = importFresh(configPath) as Partial; diff --git a/website/docs/cli.md b/website/docs/cli.md index 3357e8739de2..66c41ffe0c2f 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -49,7 +49,7 @@ Builds and serves a preview of your site locally with [Webpack Dev Server](https | `--host` | `localhost` | Specify a host to use. For example, 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). | +| `--poll [optionalIntervalMs]` | `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