如何在Vue-cli项目中更改端口号,使其在另一个端口上运行而不是8080。


当前回答

vue-cli版本3的另一种方法是在根项目目录中添加一个.env文件(与package.json一起),内容如下:

端口= 3000

运行npm run serve现在将指示应用程序在端口3000上运行。

其他回答

将PORT环境变量添加到package.json中的服务脚本中:

"serve": "PORT=4767 vue-cli-service serve",

最好的方法是更新包中的serve脚本命令。json文件。只需像这样追加——port 3000:

"scripts": {
  "serve": "vue-cli-service serve --port 3000",
  "build": "vue-cli-service build",
  "inspect": "vue-cli-service inspect",
  "lint": "vue-cli-service lint"
},

你应该擅长这个:

“serve”:“vue-cli-service service——port 8081”,

如果你使用纱线:

yarn serve --port 3000

如果你想改变localhost端口,你可以改变package.json中的scripts标签:

 "scripts": {
    "serve": "vue-cli-service serve --port 3000",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },