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

前端 未结 2 739
自闭症患者
自闭症患者 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:11

    I don't believe there is an option to do environment specific assets. But you can make additional apps in your angular-cli.json which are basically just copies of each other, but with different assets. For example

    // angular-cli.json
    "apps": [
        {
            "root": "src",
            "outDir": "dist",
            "name": "devApp",
            "assets" : [
                "assets",
                "favicon.ico",
                {
                    "glob": "**/*",
                    "input": "../externalDir",
                    "output": "./app/",
                    "allowOutsideOutDir": true
                },
            ],
            ...
        },
        {
            "root": "src",
            "outDir": "dist",
            "name": "prodApp",
            "assets": [
                "assets",
                "favicon.ico"
            ],
            ...
        }
    ]
    

    Now you can build your assets differently by building a specific "app"

    // dev
    ng build --app=0
    // or
    ng build --app=devApp
    
    // prod
    ng build --app=1
    // or
    ng build --app=prodApp
    

    Angular cli docs on multiple apps.

提交回复
热议问题