简体   繁体   English

使用文件路径进行 angular.json 配置

[英]Use a filepath for angular.json configuration

I have few different configurations for different environments and clients in my angular.json file.我的 angular.json 文件中有针对不同环境和客户端的几种不同配置。

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?我的问题是,如果有一种方法,而不是在 angular.json 中键入所有配置,而是仅为每个特定配置指定 json 文件的文件路径?

An approach for this is to create an npm script that updates the angular.json with the required configurations一种方法是创建一个npm脚本,用所需的配置更新angular.json

"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 eg --config=client - here's a good article to follow for the arguments: Pass arguments from the command line to a Node script在您的config-angular.js文件中,您会阅读参数,例如--config=client - 这里有一篇关于参数的好文章: 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).然后,您可以使用导入的client-config.js文件(或任何配置名称)的内容更新angular.json There's a lot of helper npm modules for reading and writing to and from JS/JSON files有很多帮助npm模块用于读取和写入 JS/JSON 文件

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如果您采用这种方法,最好为config-angular.js编写单元测试,并在每次更新之前输出 angular.json 文件的备份

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM