我想用5000而不是4200。
我尝试在根名称ember-cli上创建一个文件,并按照下面的代码放置JSON:
{
"port": 5000
}
但我的应用程序仍然运行在4200,而不是5000
我想用5000而不是4200。
我尝试在根名称ember-cli上创建一个文件,并按照下面的代码放置JSON:
{
"port": 5000
}
但我的应用程序仍然运行在4200,而不是5000
当前回答
简单设置在包中。json文件
"scripts": {
"ng": "ng",
"start": "ng serve --port 3000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
然后运行命令
npm start
其他回答
如果你有多个环境,你可以在angular.json中添加如下方式:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your_project:build"
},
"configurations": {
"production": {
"browserTarget": "your_project:build:production"
},
"es5": {
"browserTarget": "your_project:build:es5"
},
"local": {
"browserTarget": "your_project:build:local",
"port": 4201
},
"uat": {
"browserTarget": "your_project:build:uat"
}
}
},
这样只有本地指向另一个端口。
在CLI的最新版本(我使用的是6.0.1)中,情况似乎发生了变化。我可以通过在项目的angular.json中添加一个port选项来改变ng serve使用的默认端口:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"projects": {
"my-project": {
"architect": {
"serve": {
"options": {
"port": 4201
}
}
}
}
}
}
(本例中只显示相关属性。)
你也可以在通常输入NPM start的angular cli中输入下面的命令
Ng服务器——主机“ip-address”——端口“port-number”
对于角10+:
导航到angular。json文件。 搜索“serve”字段。 在“服务”下面是“选项”字段(如果不存在,添加选项字段)。 将这一行添加到“options”: "port": 4333(你想要的任何端口)。
例子:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 4333
},
"configurations": {
"production": {
"browserTarget": "dashboard:build:production"
}
}
},
在angular项目中更改端口号的方法:
Node_modules \ @angular-devkit\build-angular\src\dev-server\schemaJson文件
"port": {
"type": "number",
"description": "Port to listen on.",
"default": <<port number>> /* write your required port number here */
}
使用以下命令运行项目
ng serve --port <<port number>> --open
在角。json文件
"server": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "projectname:build",
"port": 5000 /* add this part */
}
adding this part and starting the server.