我需要使用fileReplacements
替换Angular应用程序中的文件,但似乎仅在build
配置中可用,而在serve
配置中不可用。
以下是我的angular.json
的摘录:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "SupplierPortal:build"
},
"configurations": {
"production": {
"browserTarget": "SupplierPortal:build:production"
},
"fr": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.fr.ts"
}
],
"browserTarget": "SupplierPortal:build:fr"
}
}
但是编译器抱怨:
架构验证失败,并出现以下错误:
数据路径“”不应具有其他属性(fileReplacements)。
是否可以针对各种服务构建进行配置?
答案 0 :(得分:1)
您几乎明白了。在构建配置中指定了fileReplacements之后,只需告知服务配置要使用哪个构建配置即可。
然后您可以执行ng serve -c=fr
,然后服务将应用 fr 构建配置:
{
"build": {
"builder": "@angular-devkit/build-angular:browser",
"configurations": {
"fr": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.fr.ts"
}]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "SupplierPortal:build"
},
"configurations": {
"production": {
"browserTarget": "SupplierPortal:build:production"
},
"fr": {
"browserTarget": "SupplierPortal:build:fr"
}
}
}
}