如果fileReplacements
中出现文件,则assets
不会替换文件。
该代码在Angular 9中不起作用,但在版本8中起作用:
"assets": [
"src/web.config"
]
...
"fileReplacements": [
{
"replace": "src/web.config",
"with": "src/configs/web.stage.config"
}
]
如何解决?
答案 0 :(得分:9)
您应该使用assets属性而不是文件替换来复制资产。
这是我的angular.json
文件的简化,仅显示了configurations
下的相关属性。
{
"projects": {
"my-project": {
"architect": {
"build": {
"configurations": {
"staging": {
"assets": [
{ "glob": "**/*", "input": "src/assets/", "output": "/assets/" },
{ "glob": "web.config", "input": "src/environments/staging/", "output": "/" }
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
]
},
"production": {
"assets": [
{ "glob": "**/*", "input": "src/assets/", "output": "/assets/" },
{ "glob": "web.config", "input": "src/environments/prod/", "output": "/" }
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
}
}
}
}
}
答案 1 :(得分:1)
我在angular 9上遇到了同样的问题,并将“ @ angular-devkit / build-angular” 从版本 ^ 0.1000.3 降级到 ^ 0.900。 7 达到了目的