如果assets
中存在文件,则Angular的fileReplacements
不会替换文件。 这段代码在Angular 9中不起作用,但在8版本中有效:
"assets": [
"src/web.config"
]
...
"fileReplacements": [
{
"replace": "src/web.config",
"with": "src/configs/web.stage.config"
}
]
如何修复?
如果assets
中存在文件,则Angular的fileReplacements
不会替换文件。 这段代码在Angular 9中不起作用,但在8版本中有效:
"assets": [
"src/web.config"
]
...
"fileReplacements": [
{
"replace": "src/web.config",
"with": "src/configs/web.stage.config"
}
]
如何修复?
你应该使用资源属性来复制资产,而不是文件替换。
这是我的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"
}
]
}
}
}
}
}
}
}