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


当前回答

第一选择:

打开的包。在“serve”部分中添加“——port port-no”。

就像下面,我已经做到了。

{
  "name": "app-name",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve --port 8090",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
}

第二个选项:如果你想通过命令提示符

运行NPM服务——端口8090

其他回答

在webpack.config.js中:

module.exports = {
  ......
  devServer: {
    historyApiFallback: true,
    port: 8081,   // you can change the port there
    noInfo: true,
    overlay: true
  },
  ......
}

您可以在模块中更改端口。exports -> devServer ->端口。

然后你重新启动npm run dev。你可以得到那个。

你应该擅长这个:

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

如果你通过Visual Studio Community或Professional(可能是. net Core项目)运行这个程序,你会发现无论你执行什么步骤,当你启动解决方案时,它都会使用8080。

有发射。Json文件,你需要编辑隐藏在.vscode目录。 MS根本没有告诉你这个,文件搜索似乎也找不到它。

打开package.json 添加名为serve的脚本,"serve": "Vue-cli-service serve -port 8081" NPM运行服务 服务器将运行8081

{
  "name": "app-name",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve --port 8081", 
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  }
}

Vue-cli webpack模板的端口在你的应用根目录myApp/config/index.js中。

你所要做的就是在dev块中修改端口值:

 dev: {
    proxyTable: {},
    env: require('./dev.env'),
    port: 4545,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    cssSourceMap: false
  }

现在你可以用localhost:4545访问你的应用了

如果你有。env文件,最好从那里设置