Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev build): reserving unused port #26 #30

Merged
merged 4 commits into from
Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
const serveStatic = require('koa-static')
const HTMLPlugin = require('html-webpack-plugin')
const history = require('connect-history-api-fallback')
const portfinder = require('portfinder')

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

const compiler = webpack(config)
const port = cliOptions.port || options.siteConfig.port || 8080
portfinder.basePort = cliOptions.port || options.siteConfig.port || 8080
const port = await portfinder.getPortPromise()
.then((port) => {
return port
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.then here can be removed if you only want to get the available port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulivz Thanks!!
completely missed it , will fix it now.

})
.catch(err => console.log(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to catch here, this should propagate up the call stack and be logged anyway.


let isFirst = true
compiler.hooks.done.tap('vuepress', () => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"nprogress": "^0.2.0",
"object-assign": "^4.1.1",
"optimize-css-assets-webpack-plugin": "^4.0.0",
"portfinder": "^1.0.13",
"postcss-loader": "^2.1.3",
"prismjs": "^1.13.0",
"register-service-worker": "^1.2.0",
Expand Down