Skip to content

ng build and serve have different behaviour in overwriting assets when using assets key in angular.json #19157

Closed
@jerbob92

Description

@jerbob92

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

We did not have to use the assets before as on earlier versions this also worked using fileReplacements, and that worked correctly in both ng serve and ng build. This sounds a little like #16670

Description

When using the assets key in the angular.json file, and having a rule that overlaps:

              "assets": [
                "src/favicon.ico",
                "src/assets",
                {
                  "input": "src/assets-replace",
                  "output": "/assets",
                  "glob": "**/*"
                }
              ]

The files from src/assets-replace will overwite the files in src/assets when using ng build, but it does not when using ng serve.

We use this functionality to have different themes of our own app. We use a different configuration for each theme, and have files with the same filename to replace the original logo, like the logo. This not working makes it a little hard to test whether theme changes work correctly.

🔬 Minimal Reproduction

  • Change angular.json, see assets example above.
  • Add an image.png in your assets folder, and display/show it in a component
  • Add an assets-replace folder in your src folder and put another image.png in it
  • Execute ng serve and see that it will display the image from src/assets
  • Execute ng build and see that it will display the image from src/assets-replace

Example repro repo: https://github.com/jerbob92/angular-cli-assets-overwrite-bug

🌍 Your Environment


Angular CLI: 10.1.7
Node: 12.19.0
OS: linux x64

Angular: 10.1.6
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1001.7
@angular-devkit/build-angular   0.1001.7
@angular-devkit/core            10.1.7
@angular-devkit/schematics      10.1.7
@angular/cli                    10.1.7
@schematics/angular             10.1.7
@schematics/update              0.1001.7
rxjs                            6.6.3
typescript                      4.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions