How to change Port number in Vue-cli project so that it run's on another port instead of 8080.
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- Vue.js - set slot content programmatically
- Simple vue app doesn't show anything
- Is it possible to pass command-line arguments to @
- Getting Uncaught TypeError: …default is not a cons
相关文章
- Linux - change the hostname in the CLI
- Best way to dynamically change theme of my Vue.js
- vue-router how to persist navbar?
- How to Properly Use Vue Router beforeRouteEnter or
- Difference between nameFunction() {} and nameFunct
- Vue - best way to reuse methods
- setTimeout() not working called from vueJS method
- How to unbind an array copy in Vue.js
As the time of this answer's writing (May 5th 2018),
vue-cli
has its configuration hosted at<your_project_root>/vue.config.js
. To change the port, see below:Full
vue.config.js
reference can be found here: https://cli.vuejs.org/config/#global-cli-configNote that as stated in the docs, “All options for webpack-dev-server” (https://webpack.js.org/configuration/dev-server/) is available within the
devServer
section.There are a lot of answers here varying by version, so I thought I'd confirm and expound upon Julien Le Coupanec's answer above from October 2018 when using the Vue CLI. In the most recent version of Vue.js as of this post - vue@2.6.10 - the outlined steps below made the most sense to me after looking through some of the myriad answers in this post. The Vue.js documentation references pieces of this puzzle, but isn't quite as explicit.
package.json
file in the root directory of the Vue.js project.package.json
file.Upon finding the following reference to "port", edit the
serve
script element to reflect the desired port, using the same syntax as shown below:Make sure to re-start the
npm
server to avoid unnecessary insanity.The documentation shows that one can effectively get the same result by adding
--port 8080
to the end of thenpm run serve
command like so:npm run serve --port 8080
. I preferred editing thepackage.json
directly to avoid extra typing, but editingnpm run serve --port 1234
inline may come in handy for some.Another option if you're using vue cli 3 is to use a config file. Make a
vue.config.js
at the same level as yourpackage.json
and put a config like so:Configuring it with the script:
works great but if you have more config options I like doing it in a config file. You can find more info in the docs.
In the
webpack.config.js
:You can change the port in the
module.exports
->devServer
->port
.Then you restrat the
npm run dev
. You can get that.In my vue project in visual studio code, I had to set this in /config/index.js. Change it in the:
Add the
PORT
envvariable to yourserve
script inpackage.json
: