I am creating a web site with Angular2@2.1.2. I am using Webpack with default settings (as a dependency).
Here is my package.json
\"dependencies\": {
I made this work with Angular6.
Place your robots.txt in the src folder, the same folder as the favicon.ico.
In your angular.json file
"assets": [
"src/favicon.ico",
"src/assets",
"src/robots.txt"
],
You may need to ng serve again, then point to http://localhost:4200/robots.txt
This will only work if you are not catching all unknown routes (path:'**') in your router module(s).
I wanted my robots.txt
to be in my src/assets
folder rather than just src
. I found that the following being added to my angular.json
in the assets
array did the trick:
"assets": [
"src/favicon.ico",
"src/assets",
{
"glob": "robots.txt",
"input": "src/assets",
"output": "./"
}
],
Works in Angular 10 using Angular Universal/SSR.
I have found my solution in this issue: https://github.com/angular/angular-cli/issues/1942
robots.txt is in src/ directory
Modify angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets", "robots.txt"],
....
Use the assets array to declare files you want to be placed in the root of dist/