angular-cli服务器-如何指定默认端口 [英] angular-cli server - how to specify default port
问题描述
通过ng serve
命令使用angular-cli,如何指定默认端口,这样我就不必每次都手动传递--port
标志?
Using angular-cli with the ng serve
command, how can I specify a default port so I do not need to manually pass the --port
flag every time?
我想从默认端口4200更改.
I'd like to change from the default port 4200.
推荐答案
针对@ angular/cli @ 9.x的更新:及以上
在angular.json
中,您可以为每个项目"指定一个端口
In angular.json
you can specify a port per "project"
"projects": {
"my-cool-project": {
... rest of project config omitted
"architect": {
"serve": {
"options": {
"port": 1337
}
}
}
}
}
所有可用选项:
https://angular.io/guide/workspace-config#项目工具配置选项
或者,每次运行ng serve时,您都可以这样指定端口:
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
使用这种方法,您可能希望将其放入package.json中的脚本中,以使其每次运行/与团队中的其他人共享配置更加容易:
With this approach you may wish to put this into a script in your package.json to make it easier to run each time / share the config with others on your team:
"scripts": {
"start": "ng serve --port 1337"
}
旧版
Legacy:
针对@ angular/cli final更新:
在angular-cli.json
内部,您可以指定默认端口:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Legacy-er:
在angular-cli@1.0.0-beta.22-1中进行了测试
angular-cli
中的服务器来自ember-cli
项目.
要配置服务器,请在项目根目录中创建一个.ember-cli
文件.在其中添加您的JSON配置:
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
重新启动服务器,它将在该端口上服务.
Restart the server and it will serve on that port.
此处指定了更多选项: http://ember-cli.com/#runtime-configuration
There are more options specified here: http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
这篇关于angular-cli服务器-如何指定默认端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!