From f2a8229e2dbba3090250b8e753593181926a9fd1 Mon Sep 17 00:00:00 2001 From: Fady Samir Sadek Date: Sun, 15 Apr 2018 20:19:58 +0200 Subject: [PATCH] fix(dev build): use portfinder (#30) close #26 --- lib/dev.js | 4 +++- package.json | 1 + yarn.lock | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dev.js b/lib/dev.js index 3b95a09680..601ff4c2e1 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -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') @@ -71,7 +72,8 @@ 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() let isFirst = true compiler.hooks.done.tap('vuepress', () => { diff --git a/package.json b/package.json index 7a988b43cb..97da12e002 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,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", diff --git a/yarn.lock b/yarn.lock index 15442de3ef..b3bced4acd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -298,6 +298,10 @@ async-limiter@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.0.tgz#78faed8c3d074ab81f22b4e985d79e8738f720f8" +async@^1.5.2: + version "1.5.2" + resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" + asynckit@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" @@ -4229,6 +4233,14 @@ pn@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" +portfinder@^1.0.13: + version "1.0.13" + resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.13.tgz#bb32ecd87c27104ae6ee44b5a3ccbf0ebb1aede9" + dependencies: + async "^1.5.2" + debug "^2.2.0" + mkdirp "0.5.x" + posix-character-classes@^0.1.0: version "0.1.1" resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"