Skip to content

Commit

Permalink
fix: default to localhost on windows (close #221)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 23, 2018
1 parent e680936 commit 4d5c50e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down

0 comments on commit 4d5c50e

Please sign in to comment.