feat(v2): Add console output with complete URL including the baseUrl (#3541)

* Add console output with complete URL including the baseUrl

* Add output when website loads for first time, corrects sentence for clarity
This commit is contained in:
Utkarsh Goel 2020-10-06 19:19:11 +08:00 committed by GitHub
parent 10973476ff
commit 2e9854964d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 <script> injected.