在配置文件中为 ng serve 设置默认主机和端口 [英] Set default host and port for ng serve in config file
本文介绍了在配置文件中为 ng serve 设置默认主机和端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在配置文件中设置主机和端口,这样我就不必键入
I want to know if i can set a host and a port in a config file so I don't have to type
ng serve --host foo.bar --port 80
而不仅仅是
ng serve
推荐答案
Angular CLI 6+
在最新版本的 Angular 中,这是在 angular.json
中设置的配置文件.示例:
Angular CLI 6+
In the latest version of Angular, this is set in the angular.json
config file. Example:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"projects": {
"my-project": {
"architect": {
"serve": {
"options": {
"port": 4444
}
}
}
}
}
}
您还可以使用ng config
查看/编辑值:
You can also use ng config
to view/edit values:
ng config projects["my-project"].architect["serve"].options {port:4444}
Angular CLI <6
在以前的版本中,这是在 angular-cli.json 中设置的
在 defaults
元素下面:
{
"defaults": {
"serve": {
"port": 4444,
"host": "10.1.2.3"
}
}
}
这篇关于在配置文件中为 ng serve 设置默认主机和端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文