diff --git a/packages/docusaurus/src/commands/start.ts b/packages/docusaurus/src/commands/start.ts index 0e6ab94884..673fd1bb72 100644 --- a/packages/docusaurus/src/commands/start.ts +++ b/packages/docusaurus/src/commands/start.ts @@ -37,11 +37,33 @@ export default async function start( // Process all related files as a prop. const props = await load(siteDir); + const protocol: string = process.env.HTTPS === 'true' ? 'https' : 'http'; + + const host: string = getCLIOptionHost(cliOptions.host); + const port: number | null = await getCLIOptionPort(cliOptions.port, host); + + if (port === null) { + process.exit(); + } + + const {baseUrl, headTags, preBodyTags, postBodyTags} = props; + const urls = prepareUrls(protocol, host, port); + const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]); + + console.log(chalk.cyanBright(`Docusaurus website is running at: ${openUrl}`)); + // Reload files processing. const reload = () => { - load(siteDir).catch((err) => { - console.error(chalk.red(err.stack)); - }); + load(siteDir) + .then(({baseUrl: newBaseUrl}) => { + const newOpenUrl = normalizeUrl([urls.localUrlForBrowser, newBaseUrl]); + console.log( + chalk.cyanBright(`Docusaurus website is running at: ${newOpenUrl}`), + ); + }) + .catch((err) => { + console.error(chalk.red(err.stack)); + }); }; const {siteConfig, plugins = []} = props; @@ -67,19 +89,6 @@ export default async function start( fsWatcher.on(event, reload), ); - const protocol: string = process.env.HTTPS === 'true' ? 'https' : 'http'; - - const host: string = getCLIOptionHost(cliOptions.host); - const port: number | null = await getCLIOptionPort(cliOptions.port, host); - - if (port === null) { - process.exit(); - } - - const {baseUrl, headTags, preBodyTags, postBodyTags} = props; - const urls = prepareUrls(protocol, host, port); - const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]); - let config: webpack.Configuration = merge(createClientConfig(props), { plugins: [ // Generates an `index.html` file with the