feat(v2): report port number when starting dev server (#1582)

* feat(v2): report port number when starting dev server

* Attempt to print dev server URL

* Use digit dino

* Resolve merge conflict

* remove dino
This commit is contained in:
Wei Gao 2019-06-24 16:17:13 +08:00 committed by Endi
parent 80df0c00f2
commit a6736dd8dc
2 changed files with 5 additions and 2 deletions

View file

@ -19,9 +19,9 @@ import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import merge from 'webpack-merge';
import HotModuleReplacementPlugin from 'webpack/lib/HotModuleReplacementPlugin';
import {CONFIG_FILE_NAME, STATIC_DIR_NAME} from '../constants';
import {load} from '../server';
import {CLIOptions} from '../server/types';
import {CONFIG_FILE_NAME, STATIC_DIR_NAME, DEFAULT_PORT} from '../constants';
import {createClientConfig} from '../webpack/client';
import {applyConfigureWebpack} from '../webpack/utils';
@ -30,7 +30,7 @@ function getHost(reqHost: string | undefined): string {
}
async function getPort(reqPort: string | undefined): Promise<number> {
const basePort = reqPort ? parseInt(reqPort, 10) : 3000;
const basePort = reqPort ? parseInt(reqPort, 10) : DEFAULT_PORT;
const port = await portfinder.getPortPromise({port: basePort});
return port;
}
@ -79,6 +79,8 @@ export async function start(
const urls = prepareUrls(protocol, host, port);
const openUrl = normalizeUrl([urls.localUrlForBrowser, baseUrl]);
console.log(chalk.cyan(`Your site will be accessible at ${openUrl}`));
let config: webpack.Configuration = merge(createClientConfig(props), {
plugins: [
// Generates an `index.html` file with the <script> injected.

View file

@ -11,3 +11,4 @@ export const GENERATED_FILES_DIR_NAME = '.docusaurus';
export const SRC_DIR_NAME = 'src';
export const STATIC_DIR_NAME = 'static';
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
export const DEFAULT_PORT = 3000;