Different assets in cli config for ng serve and ng build [Angular 5]

前端 未结 2 744
自闭症患者
自闭症患者 2021-01-06 08:27

Is possible to use different assets array when i use ng build?

\"assets\": [
  \"assets\",
  \"favicon.ico\",
  {
    \"glob\": \"**/*\",
    \"         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-06 09:23

    My case was to include different robots.txt file per environment. So, in the src/environments folder I created two files: robots.txt and robots.prod.txt. In angular.json include it in assets array and use fileReplacements as follow (I paste only the relevant parts):

    "architect": {
      "build": {
        "options": {
          "assets": [
            "src/assets",
            {
              "glob": "robots.txt",
              "input": "src/environments/",
              "output": "/"
            }
          ]
        },
        "configurations": {
          "production": {
            "fileReplacements": [
              {
                "replace": "src/environments/robots.txt",
                "with": "src/environments/robots.prod.txt"
              }
            ]
          }
        }
      }
    }
    

    I am using @angular/cli: ~8.3.4.

提交回复
热议问题