How to dynamically build angular.json file?

51 Views Asked by At

What I need? I want a convenient and easy way to create configuration for an Angular application (which is described in the angular.json file) on the fly. The same way this is done, for example, with Webpack or Tailwind configs (their configs can be .js files that simply export the config as an object).

Why is this necessary? It so happened that my project has a lot of build configurations. Therefore, the angular.json file becomes simply huge and very difficult to maintain. Many parts of the config are repeated, because some blocks (for example, fileReplacements and assets) have to be written in full each time, because angular.json does not have a mechanism for inheriting configurations.

How do I solve the problem now? I simply created a .ts script that creates the angular.json file I need. And I run this file before each ng build or ng serve command. There are a couple of disadvantages to this approach.

  1. For the Angular configuration, there is not even TypeScript typing for the hints to work.
  2. Every time the configuration changes, I have to manually stop and rebuild the application from scratch. Although if you change angular.json directly, then Angular sees this change and rebuilds the application on the fly.

Is there an adequate solution for this problem? Maybe a more elegant way? Maybe it is possible to use the angular.js file instead of angular.json in some native way, but this is not in the documentation?

0

There are 0 best solutions below