为了在ng build中也能使用fileReplacements,需要在angular.json中进行配置。例如,为了替换一个名为“environment.ts”的文件,在“build”部分中的“configurations”中添加一个新的“production”环境,并'fileReplacements”设置为所需的文件路径,如下所示:
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
// Other production configuration options...
}
}
然后运行“ng build --configuration=production” 就能够在构建时使用fileReplacements了。