Skip to content

Commit 4d5c50e

Browse files
committed
fix: default to localhost on windows (close #221)
1 parent e680936 commit 4d5c50e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/dev.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
7373
}
7474

7575
const compiler = webpack(config)
76-
const host = cliOptions.host || options.siteConfig.host || '0.0.0.0'
76+
// webpack-serve hot updates doesn't work properly over 0.0.0.0 on Windows,
77+
// but localhost does not allow visiting over network :/
78+
const defaultHost = process.platform === 'win32' ? 'localhost' : '0.0.0.0'
79+
const host = cliOptions.host || options.siteConfig.host || defaultHost
80+
const displayHost = host === defaultHost && process.platform !== 'win32'
81+
? 'localhost'
82+
: host
7783
portfinder.basePort = cliOptions.port || options.siteConfig.port || 8080
7884
const port = await portfinder.getPortPromise()
7985

@@ -83,7 +89,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
8389
isFirst = false
8490
console.log(
8591
`\n VuePress dev server listening at ${
86-
chalk.cyan(`http://${host === '0.0.0.0' ? 'localhost' : host}:${port}${options.publicPath}`)
92+
chalk.cyan(`http://${displayHost}:${port}${options.publicPath}`)
8793
}\n`
8894
)
8995
} else {

0 commit comments

Comments
 (0)