Angular-cli: Default projects and configurations

Created on 13 Jun 2018  路  7Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Area

- [x] devkit
- [ ] schematics

We have many projects in the repository and now there is a lot of copy-paste in the angular.json

There is a proposal to add defaultConfigurations, defaultProjects and be able to inherit that.

Example

{
  "defaultProjects": {
    "defaultApp": {
      "root": "apps/$appName",
      "sourceRoot": "apps/$appName/src",
      "projectType": "application"
    }
  },
  "defaultConfigurations": {
    "defaultProd": {
      "aot": true,
      "optimization": true,
      "sourceMap": true,
      "outputHashing": "all",
      "namedChunks": false,
      "commonChunk": true,
      "buildOptimizer": true
    }
  },
  "projects": {
    "app": {
      "extend": "defaultApp",
      "configurations": {
        "prod": {
          "extend": "defaultProd",
          "extractCss": true,
          "extractLicenses": true,
          "vendorChunk": false
        }
      }
    }
  }
}
feature

Most helpful comment

Dear Angular Team, do you consider adding this anytime soon?

All 7 comments

Would love to see that, too! I have two apps already that need exactly this:

The app is the same but depending on the build the assets, styles or even some components need to change. This is already possible by use of the projects or configuration and then ng build customer1, ng build customer1 OR ng build configuration=customer1 and ng build configuration=customer2. But without extend functionality this creates TONS of duplicate configration code.

Btw. file replacement for all file types is already implemented in upcoming release 6.1.0. E.g. you can then replace component-a.ts with component-b.ts for one build. Anyway, without the extend functionality, we have to create tons of duplicate code as you mentioned.

Dear Angular Team, do you consider adding this anytime soon?

Do you think it's possible to achieve with schematics? I'm thinking about having a template config and expand it to many variations into angular.json with some schematic or NodeJS script. What do you think?

I am generally wary of the "autogenerate lots of clunky configuration" idea.
It tends to be brittle, in particular between updates, and makes things hard to debug as we essentially invent yet another language. This was the "Turing-complete XML configuration" hell Java went through, with the same vision of "you just need to right-click in your IDE and not worry about the 400Kb XML which suddenly appeared. (Except when something _did_ go wrong, as it inevitably will)".

But other option is only a lot of error-prone and tedious manual updates.

Heya, this request looks to be very similar to https://github.com/angular/angular-cli/issues/10612. I'm closing in favor of that one to keep the discussion in one place.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajjejosefsson picture rajjejosefsson  路  3Comments

daBishMan picture daBishMan  路  3Comments

brtnshrdr picture brtnshrdr  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments

ericel picture ericel  路  3Comments