1

I have few different configurations for different environments and clients in my angular.json file.

My question is, if there is a way to, instead of typing all the configurations inside angular.json, specify just the file path to json file for each specific configuration?

2
  • In an angular app you have one angular.json even if you have multiple projects in it. Commented Jan 18, 2020 at 12:07
  • What I want to do is to specify in angular.json paths to different configurations, let's say client.config.json, que not to create multiple angular.json files Commented Jan 18, 2020 at 12:55

1 Answer 1

1

An approach for this is to create an npm script that updates the angular.json with the required configurations

"scripts": {
    "start": "ng serve",
    "build": "ng build",
    "config:angular": "node config-angular.js"

}

// on the command line
npm run config:angular -- --config=client

In your config-angular.js file you'd read the arguments e.g. --config=client - here's a good article to follow for the arguments: Pass arguments from the command line to a Node script

You can then update the angular.json with the contents of an imported client-config.js file (or whatever the configs are names). There's a lot of helper npm modules for reading and writing to and from JS/JSON files

If you're taking this approach it's a good idea to write a unit test for config-angular.js, and also to output a backup of the angular.json file before each update

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.