Skip to content

Commit ac68434

Browse files
fix(dev build): reserving unused port vuejs#26
1 parent 86d4055 commit ac68434

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/dev.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
1010
const serveStatic = require('koa-static')
1111
const HTMLPlugin = require('html-webpack-plugin')
1212
const history = require('connect-history-api-fallback')
13+
const portfinder = require('portfinder')
1314

1415
const prepare = require('./prepare')
1516
const HeadPlugin = require('./webpack/HeadPlugin')
@@ -71,7 +72,12 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
7172
}
7273

7374
const compiler = webpack(config)
74-
const port = cliOptions.port || options.siteConfig.port || 8080
75+
portfinder.basePort = cliOptions.port || options.siteConfig.port || 8080
76+
const port = await portfinder.getPortPromise()
77+
.then((port) => {
78+
return port
79+
})
80+
.catch(err => console.log(err))
7581

7682
let isFirst = true
7783
compiler.hooks.done.tap('vuepress', () => {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"nprogress": "^0.2.0",
7070
"object-assign": "^4.1.1",
7171
"optimize-css-assets-webpack-plugin": "^4.0.0",
72+
"portfinder": "^1.0.13",
7273
"postcss-loader": "^2.1.3",
7374
"prismjs": "^1.13.0",
7475
"register-service-worker": "^1.2.0",

0 commit comments

Comments
 (0)