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
The port for the Vue-cli webpack template is found in your app root's
myApp/config/index.js
.All you have to do is modify the
port
value inside thedev
block:Now you can access your app with
localhost:4545
also if you have
.env
file better to set it from thereGo to node_modules/@vue/cli-service/lib/options.js
At the bottom inside the "devServer" unblock the codes
Now give your desired port number in the "port" :)
Best way is to update the serve script command in your
package.json
file. Just append--port 3000
like so:If you're using
vue-cli
3.x, you can simply pass the port to thenpm
command like so:npm run serve -- --port 3000
Then visit
http://localhost:3000/
Late to the party, but I think it's helpful to consolidate all these answers into one outlining all options.
Separated in Vue CLI v2 (webpack template) and Vue CLI v3, ordered by precedence (high to low).
Vue CLI v3
package.json
: Add port option toserve
script:scripts.serve=vue-cli-service serve --port 4000
--port
tonpm run serve
, e.g.npm run serve -- --port 3000
. Note the--
, this makes passes the port option to the npm script instead of to npm itself. Since at least v3.4.1, it should be e.g.vue-cli-service serve --port 3000
.$PORT
, e.g.PORT=3000 npm run serve
.env
Files, more specific envs override less specific ones, e.g.PORT=3242
vue.config.js
,devServer.port
, e.g.devServer: { port: 9999 }
References:
Vue CLI v2 (deprecated)
$PORT
, e.g.PORT=3000 npm run dev
/config/index.js
:dev.port
References:
An alternative approach with
vue-cli
version 3 is to add a.env
file in the root project directory (along sidepackage.json
) with the contents:PORT=3000
Running
npm run serve
will now indicate the app is running on port 3000.