[英]Use a filepath for angular.json configuration
我的 angular.json 文件中有针对不同环境和客户端的几种不同配置。
我的问题是,如果有一种方法,而不是在 angular.json 中键入所有配置,而是仅为每个特定配置指定 json 文件的文件路径?
一种方法是创建一个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
在您的config-angular.js
文件中,您会阅读参数,例如--config=client
- 这里有一篇关于参数的好文章: Pass arguments from the command line to a Node script
然后,您可以使用导入的client-config.js
文件(或任何配置名称)的内容更新angular.json
。 有很多帮助npm
模块用于读取和写入 JS/JSON 文件
如果您采用这种方法,最好为config-angular.js
编写单元测试,并在每次更新之前输出 angular.json 文件的备份
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.