【问题标题】:Difference between ng serve --port 4200 and ng serve --host ip:4200ng serve --port 4200 和 ng serve --host ip:4200 的区别
【发布时间】:2020-03-08 02:09:48
【问题描述】:

如何通过 ng serve 命令在我的本地主机中的同一个端口上为 Angular 应用程序提供服务,并在我的路由器分配的 IPv4 地址中通过 ng serve --host 192.168.12.100 在同一端口上运行,即 4200 和我不能使用 ng serve 让两个应用程序在同一个端口上运行两次它给出错误另一个应用程序在同一个端口上运行我也知道我们可以通过 ng serve --port 4000 更改默认端口

在不同的环境中运行相同的应用程序两次

服务 ng 服务 --host ip

这里的ip是分配给系统的IPv4地址

【问题讨论】:

    标签: angular


    【解决方案1】:
    ng serve --port 4200 :
    

    只需更改端口号,但主机保持不变默认主机是“localhost”

    and ng serve --host ip:4200 :
    

    它更改 IP 或域示例 abc.com

    或者您可以更改angular-cli.json 或angular.json

    {
      "defaults": {
        "serve": {
          "port": 4444,
          "host": "10.1.2.3"
        }
      }
    }
    

    【讨论】:

    • 是的,我知道如何更改 ip,但我试图理解 ng serve --port 4200 和 ng serve --host ip:4200 在同一个端口上运行而不会导致任何错误。
    • 这个答案需要更新。我认为 angular.json 不再支持“默认”属性。我正在使用 angular-cli 版本 8.3.22。当我阅读 ./node_modules/@angular/cli/lib/config/schema.json 中的 json 模式时,我看不到 defaults 那里的属性。我对架构的解读是:可以在“serve”(查找“@angular-devkit/build-angular:dev-server”)下添加port 属性->“options”属性或“下的配置对象之一”配置”,如果你想根据运行配置使用不同的端口。
    猜你喜欢
    • 2018-04-19
    • 2016-12-29
    • 2019-12-24
    • 2018-02-07
    • 2019-06-16
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多