Angular 6+ 如何更改默认端口 4200

标签 angular port angular-cli-v6

这个问题特定于 Angular 版本 6,而不是更早版本,因为 .angular-cli.json 文件已被 angular.json 文件替换。

我创建了一个新的 Angular 6 项目,并像以前的版本一样尝试更改其默认端口,但这次是在 angular.json 中。

  "defaults": {
    "serve": {
      "port": 4220
  },  

但是得到如下错误:

Invalid schema detected in .angular-cli.json, please correct and try again!

有人知道如何使用这个新版本的 Angular 做到这一点吗?

最佳答案

由于标题不准确:“angular-cli server - how to specify default port”,很难找到我的问题的答案,但多亏了 Vladymir Gonzalez,我找到了。

为了帮助其他人快速找到答案,我在这里提取了 Angular 6 的特定部分,属于 elwyn :

@angular/cli@6.x 的更新:在新的 angular.json 中,您现在为每个“项目”指定一个端口

"projects": {
    "my-cool-project": {
        ... rest of project config omitted
        "architect": {
            "serve": {
                "options": {
                    "port": 4850    <-- add your custom port number here      
                }
            }
        }
    }
}

所有可用选项:

https://github.com/angular/angular-cli/wiki/angular-workspace

关于Angular 6+ 如何更改默认端口 4200,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50519121/

相关文章:

javascript - 捆绑我的 JS/TS 项目是反模式吗?

linux - 监听网络端口并将数据保存到文本文件

angular - 构建具有多个配置的应用程序

angular - 如何让 ng 构建观看多个应用程序?

angular - Font Awesome + Electron

css - Angular 2 : change background color of div when checkbox is checked

angular - 如何在Angular 2+中实现录音机并将其下载为HTML音频文件

python - 如何为 python 客户端提供来自 python 服务器的端口号

tomcat - 负载均衡以暴露单个端口

angular - 是否可以使用单个 angular-cli 命令生成多个 Angular 组件,例如 ng generate component comp1, comp2, comp3?