我正在运行Visual Studio 2017 Angular SPA模板,我想增加使用角度环境变量来进行生产和开发。
我正在package.json
文件中运行以下版本的angular;
"@angular/animations": "^4.4.7",
"@angular/cli": "^6.0.8",
"@angular/common": "^4.4.7",
"@angular/compiler": "^4.4.7",
"@angular/compiler-cli": "^4.4.7",
"@angular/core": "^4.4.7",
"@angular/forms": "^4.4.7",
"@angular/http": "^4.4.7",
"@angular/platform-browser": "^4.4.7",
"@angular/platform-browser-dynamic": "^4.4.7",
"@angular/platform-server": "^4.4.7",
"@angular/router": "^4.4.7",
我已经在/environments
文件夹中创建了ClientApp/app
文件夹,并添加了environment.prod.ts
和environment.ts
文件。
一个例子是;
export const environment = {
production: false,
appUrl: 'http://localhost:61996',
apiUrl: 'http://localhost:61996'
};
然后如何配置它以使其与SPA一起使用?由于当前模板不包含我在教程网站上引用的.angular-cli.json
文件?
我的目标是能够在发布时使用'environment.prod.ts and then web deploy the
environment.ts`在调试中运行。
答案 0 :(得分:0)
在angular.json
中,有一个配置部分,您可以在其中定义fileReplacement。
"build": {
"configurations": {
"dev": {
"fileReplacements": [ {
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}]
},
"prod": {
"fileReplacements": [ {
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}]
}
}
}
要使用 dev环境,您必须添加--configuration=dev