这个问题特定于 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/