Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the default port from 8080 to something else in Vue?

I have been working on Vue.js and Node.js to build my app. When I have started with Vue it is by default running on 8080 and Node I am running on 3008.

What I am trying to do is due to some circumstances I want to change the port for Vue from 8080 to any other like 8086 or 3005. How can I do that?

like image 950
manish thakur Avatar asked Oct 04 '19 06:10

manish thakur


People also ask

What server does Vue CLI use?

The vue-cli-service serve command starts a dev server (based on webpack-dev-server) that comes with Hot-Module-Replacement (HMR) working out of the box.

How do I run a Vue project on localhost?

Open in browser To view the project, open a tab and type http://localhost:3000 into the URL bar. That's the address that the Node server is listening to. You should now see this page, which is the basic structure of our project.

What is VUE config?

vue. config. js is an optional config file that will be automatically loaded by @vue/cli-service if it's present in your project root (next to package. json ). You can also use the vue field in package.


3 Answers

Simply you can run the following command to run vue app as per your required port :

npm run serve --port 8086

Another way is to update the serve script command in your package.json file. Just append --port 8086 like so:

"scripts": {
  "serve": "vue-cli-service serve --port 8086",
  "build": "vue-cli-service build",
  "inspect": "vue-cli-service inspect",
  "lint": "vue-cli-service lint"
}
like image 197
Rahul Gupta Avatar answered Sep 24 '22 17:09

Rahul Gupta


If you don't have one create vue.config.js in the root dir of your project and there add this option:

module.exports = {
   devServer: {
      port: 8086
   }
}

In webpack docs you can see all the available options for configuring the dev server.

Check also vue-cli docs.

like image 38
Slim Avatar answered Sep 22 '22 17:09

Slim


This is the way! ...that worked for me!

npm run serve -- --port 8086
like image 41
virtuvious Avatar answered Sep 23 '22 17:09

virtuvious