diff --git a/lib/dev.js b/lib/dev.js index 7cc6e2d5b8..6205cae828 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -73,7 +73,13 @@ module.exports = async function dev (sourceDir, cliOptions = {}) { } const compiler = webpack(config) - const host = cliOptions.host || options.siteConfig.host || '0.0.0.0' + // webpack-serve hot updates doesn't work properly over 0.0.0.0 on Windows, + // but localhost does not allow visiting over network :/ + const defaultHost = process.platform === 'win32' ? 'localhost' : '0.0.0.0' + const host = cliOptions.host || options.siteConfig.host || defaultHost + const displayHost = host === defaultHost && process.platform !== 'win32' + ? 'localhost' + : host portfinder.basePort = cliOptions.port || options.siteConfig.port || 8080 const port = await portfinder.getPortPromise() @@ -83,7 +89,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) { isFirst = false console.log( `\n VuePress dev server listening at ${ - chalk.cyan(`http://${host === '0.0.0.0' ? 'localhost' : host}:${port}${options.publicPath}`) + chalk.cyan(`http://${displayHost}:${port}${options.publicPath}`) }\n` ) } else {