From 92cbc1e85464be7dc2764a08621883461f66ae87 Mon Sep 17 00:00:00 2001 From: unclebill Date: Fri, 1 Sep 2017 10:01:18 +0800 Subject: [PATCH] Make changing port from cli possible. --- README.md | 5 ++++- template/build/dev-server.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea4c750559..023db8d1c4 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,13 @@ $ npm install -g vue-cli $ vue init webpack my-project $ cd my-project $ npm install +# run at default port 8080 $ npm run dev +# run at port 6060 +$ npm run dev -- --port 6060 ``` -If port 8080 is already in use on your machine you must change the port number in `/config/index.js`. Otherwise `npm run dev` will fail. +You can change the port at `config/index.js` as well. ## What's Included diff --git a/template/build/dev-server.js b/template/build/dev-server.js index e3c7b55708..54d4a4f4f3 100644 --- a/template/build/dev-server.js +++ b/template/build/dev-server.js @@ -16,6 +16,10 @@ var webpackConfig = {{#if_or unit e2e}}(process.env.NODE_ENV === 'testing' || pr // default port where dev server listens for incoming traffic var port = process.env.PORT || config.dev.port +var portIndex = process.argv.indexOf('--port') +if (portIndex !== -1) { + port = process.argv[portIndex + 1] || port; +} // automatically open browser, if not set will be false var autoOpenBrowser = !!config.dev.autoOpenBrowser // Define HTTP proxies to your custom API backend