diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index f66a98a79f..c8fd2b7766 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -7,6 +7,7 @@ - Add `extendCli` api for plugins. This will allow plugin to further extend Docusaurus CLI. - Fix `swizzle` command not being able to swizzle single js file. - Fix logo URL in footer to be appended with baseUrl automatically. +- Add the option `--no-open` for `start` command. ## 2.0.0-alpha.27 diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 395aff227d..e66dd7da6e 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -49,6 +49,7 @@ export interface StartCLIOptions { port: string; host: string; hotOnly: boolean; + open: boolean; } export interface BuildCLIOptions { diff --git a/packages/docusaurus/bin/docusaurus.js b/packages/docusaurus/bin/docusaurus.js index 6c61d73288..7b9824b79a 100755 --- a/packages/docusaurus/bin/docusaurus.js +++ b/packages/docusaurus/bin/docusaurus.js @@ -70,11 +70,13 @@ cli '--hot-only', 'Do not fallback to page refresh if hot reload fails (default: false)', ) - .action((siteDir = '.', {port, host, hotOnly}) => { + .option('--no-open', 'Do not open page in the browser (default: false)') + .action((siteDir = '.', {port, host, hotOnly, open}) => { wrapCommand(start)(path.resolve(siteDir), { port, host, hotOnly, + open, }); }); diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index a8a173acb8..734ea7393f 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -144,7 +144,7 @@ export async function start( if (err) { console.log(err); } - openBrowser(openUrl); + cliOptions.open && openBrowser(openUrl); }); ['SIGINT', 'SIGTERM'].forEach(sig => { process.on(sig as NodeJS.Signals, () => { diff --git a/website/docs/cli.md b/website/docs/cli.md index 3559d5eaef..c28defb8d8 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -48,6 +48,7 @@ Builds and serves the static site with [Webpack Dev Server](https://webpack.js.o |`--port`|`3000`|Specifies the port of the dev server| |`--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.| ### `docusaurus build`