当我在服务器上启动Angular项目时,我总是需要添加--disable-host-check和--host = 0.0.0.0才能使其正常工作。由于我不需要在本地开发环境中执行此操作,因此我想在我的angular.json构建配置中配置这些参数,以便我可以简单地执行
ng serve --prod
或
ng serve --configuration=staging
在我的服务器上,并在相应的构建设置中自动设置了host和disable-host-check。那可能吗?目前,我的配置如下:
"configurations": {
"develop": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
]
},
"staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
]
}
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
答案 0 :(得分:1)
您为什么不只是在package.json中为命令添加脚本,而不是弄乱angular.json文件?例如:
"scripts": {
"start": "ng serve --prod --disable-host-check --host=0.0.0.0",
}
然后称它为npm run start。