There are several ways to implement different robots.txt for the different environments.
You can create all different robots.txt like robots.txt, robots-staging.txt and robots-prod.txt.
And in the angular.json, you can change the content of robots.txt using fileReplacements while building the app depending on building mode.
{
"$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular": {
"root": "",
"projectType": "application",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/app/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.browser.json",
"deployUrl": "/",
"assets": [
{
"glob": "favicon.ico",
"input": "src",
"output": "/"
},
{
"glob": "robots.txt",
"input": "src",
"output": "/"
},
{
"glob": "**/*",
"input": "src/assets",
"output": "/assets"
}
],
"styles": [
"src/styles.scss",
],
"scripts": [
"src/assets/js/bootstrap-select.min.js",
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
},
{
"replace": "src/robots.txt",
"with": "src/robots-prod.txt"
}
],
...
}
}
},
...
}
In this case you can use CI/CD tool in order to create or change the robots.txt.
You can refer how to do that in the relevant document.
Hope this helps you!