我已经实现了应用程序配置,可以从我的角度应用程序的JSON文件中读取该配置文件,以便在部署后可以轻松配置它。 我们使用章鱼部署工具来部署角度应用程序。如您所知,将enviornment.ts文件生成为js文件,它 通过读取JS文件来操作八达通中的设置非常困难。因此,我创建了config.JSON文件,该文件将输出到dist文件夹并 章鱼部署可以在需要时使用JSON文件进行更改。
当前,应用程序正在从环境ts文件中读取值,而该文件又正在读取Config.JSON文件中设置的值。
我想知道我的方法是否正确?
Config.JSON
{
"settings": {
"production": false,
"userIdleMinutes": "10",
"corePingIntervalSeconds": "10",
"baseUrl": "http://localhost:57973",
"loginUrl": "/Login",
"adminUrl": "/Admin"
}
}
enviornment.ts
import config from '../assets/config.json'
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = {
production: config.settings.production,
baseUrl: config.settings.baseUrl,
loginUrl:config.settings.loginUrl,
adminUrl: config.settings.adminUrl,
userIdleMinutes: config.settings.userIdleMinutes,
corePingIntervalSeconds: config.settings.corePingIntervalSeconds
};
答案 0 :(得分:0)
如果您使用的是octopus
,而不是这样做,请在您的环境中。prod.ts添加一些令牌,并在每个环境中用octopus
(目前我无权向您展示操作方法,但如下所示)
environment.prod.ts
export const environment = {
production: #{production},
baseUrl: "#{baseUrl}",
//... rest of your configs
};
然后添加一个步骤,以每次部署的main.*.js
文件中的环境中定义的变量替换这些变量