Angular2 + webpack do not deploy robots.txt

后端 未结 3 1550
北海茫月
北海茫月 2020-12-31 02:33

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\": {         


        
相关标签:
3条回答
  • 2020-12-31 02:39

    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).

    0 讨论(0)
  • 2020-12-31 02:40

    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.

    0 讨论(0)
  • 2020-12-31 02:52

    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/

    0 讨论(0)
提交回复
热议问题