【问题标题】:Can I change the default port from 8080 to something else in Vue?我可以将默认端口从 8080 更改为 Vue 中的其他端口吗?
【发布时间】:2020-02-02 11:43:18
【问题描述】:

我一直在使用 Vue.js 和 Node.js 来构建我的应用程序。当我开始使用 Vue 时,它​​默认运行在 8080 上,而 Node 我运行在 3008 上。

我正在尝试做的是由于某些情况我想将 Vue 的端口从 8080 更改为 8086 或 3005 之类的任何其他端口。我该怎么做?

【问题讨论】:

标签: vue.js vuejs2 port


【解决方案1】:

您只需运行以下命令即可根据您所需的端口运行 vue 应用程序:

npm run serve --port 8086

另一种方法是更新 package.json 文件中的 serve 脚本命令。只需像这样附加--port 8086

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

【讨论】:

    【解决方案2】:

    如果您没有在项目的根目录中创建 vue.config.js 并添加此选项:

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

    webpack docs 中,您可以看到配置开发服务器的所有可用选项。

    还要检查vue-cli docs

    【讨论】:

      【解决方案3】:

      就是这样! ...这对我有用!

      npm run serve -- --port 8086
      

      【讨论】:

      • 谢谢。我使用了运行npm run serve --port 8081,但它以错误消息TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number (8081)结束。
      【解决方案4】:

      使用 “npm”

      npm run serve --port 8086
      

      使用“纱线”

      yarn serve --port 8086
      

      【讨论】:

        【解决方案5】:

        目录:node_modules@vue\cli-service\lib\commands 更改文件:serve.js

        常量默认值 = { 主机:'0.0.0.0', 端口:8086, https:假的 }

        【讨论】:

        • 你不应该直接在node_modules中改变任何东西
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-13
        • 2020-05-14
        • 2015-03-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多