我在angular.json文件中配置指向不同构建的不同"urls“
angular.json
configuration:{
'dev':{
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.qa.ts"
}
},
qa:{
}
}environment.dev.ts
export const environment = {
appServer: "https://....."
}environment.prod.ts
export const environment = {
appServer: "https://....."
}我想创建一个保存在资产中的extconfig.js文件(外部js),并将其放在angular.json文件中
config.js
var baseUrl = '' ; <==========// environment.appServer based on build condition当通过"ng serve --configuration=dev“或”ng build --configuration=prod“运行时,它应该基于构建环境来处理环境变量的"appServer”。
这是必需的,因为"extconfig.js“文件将保存全局变量,其中包含为其他外部js提供服务的配置变量,这些外部js可能需要用于ajax调用的baseUrl
发布于 2020-02-19 16:28:05
如果我理解正确的话,你可以在同一个文件夹下创建一个config.prod.ts和一个config.ts,每一个都有你的appServer url的一个版本。然后,您可以从服务中的文件夹导入您的配置。
import { extConfig } from './config-specifics';
var baseUrl = extConfig.appServerUrl
在你的angular.json里。
"fileReplacements": [
{
"replace": "apps/app-name/src/app/config-specifics/config.ts",
"with": "apps/app-name/src/app/config-specifics/config.prod.ts"
}
]https://stackoverflow.com/questions/60295438
复制相似问题