8

어떻게하면 내 각진 빌드를 사용할 수 있습니까? 모든 특정 환경에 맞게 빌드하지 않아도됩니까?각도 프로젝트에 대한 빌드 재사용 방법

실행시 환경을 각도로 조작하는 방법을 찾아야합니다!

각 환경에 대한 설정이 있으며 NG 빌드 --env = dev을 사용하고 dev 환경 용으로 빌드합니다. QA, UAT 및 프로덕션 환경에서 구성을 어떻게 변경합니까?

도구 세트 : 닷넷 비주얼 스튜디오 팀 서비스, 2

런타임에이 작업을 수행 할 수있는 방법은 없습니다 각도? 우리는 빌드 시간/디자인 타임을 고수하고 있습니까?

또한 우린 접미사가있는 URL을 기반으로 환경을 선택할 수 있습니까? https://company-fancyspawebsite-품질 보증 .azurewebsites.net

PS : 우리는 각각의 환경에 대해 각 2 개 환경 폴더 및 응용 프로그램 설정 파일을 사용하고 있습니다.

enter image description here

+1

환경마다 어떤 종류의 각도 ​​구성을 가지고 있습니까? 자세한 내용을 공유 할 수 있습니까? –

+0

[this] (https://github.com/angular/angular-cli/issues/7506), [this] (https://github.com/angular/angular-cli/issues/3855) 및 [this ] (https://github.com/angular/angular-cli/issues/2508#issuecomment-257988755) 어떻게 수행 할 수 있는지에 대한 몇 가지 접근법을 설명합니다. –

+0

우리는 각도 2 환경 폴더를 사용하고 각 환경에 대한 파일을 appsettings. –

답변

4

enter image description here

enter image description here

나는 실행시에 편집 구성 설정을 제공하기 위해 구성 서비스를 사용합니다. 내 src 폴더

{ 
    "WebApiBaseUrl": "http://myWebApi.com", 
    "EnableConsoleLogging": true, 
    "PageSize": 10 
} 

을에있는 (이 각도-CLI를 사용)

config.service.ts

import { Injectable } from '@angular/core'; 
import { Http, Headers, RequestOptions, Response } from '@angular/http'; 

export interface Config { 
    PageSize: number; 
    EnableConsoleLogging: boolean; 
    WebApiBaseUrl: string; 
} 

@Injectable() 
export class ConfigService { 
    private config: Config; 

    constructor(private http: Http) { } 

    public getConfigSettings(): Config { 
     if (!this.config) { 
      var Httpreq = new XMLHttpRequest(); 
      Httpreq.open("GET", 'config.json', false); 
      Httpreq.send(null); 

      this.config = JSON.parse(Httpreq.responseText); 

      if (this.config.EnableConsoleLogging) 
       console.log("Config loaded", this.config); 
     } 

     return this.config; 
    } 
} 

config.json는 .angular에 자산 config.json를 추가

-cli.json
{ 
    }, 
    "apps": [ 
    { 
     "assets": [ 
     "config.json" 
     ] 
    } 
    } 
} 

그것을

를 사용하는 방법
export class MyComponent { 
    private config: Config; 

    constructor(private configService: ConfigService) { 
     this.config = configService.getConfigSettings(); 

     console.log(this.config.WebApiBaseUrl); 
    } 
} 
+0

좋은 책을 읽고 바로 생각해보십시오. –

+0

답변으로 표시 할 수 없습니다. 직장 동료 인 나의 친구는 이것을 사용하고 런타임 변수를 삽입하기 위해 단일 CI 정의를 갖는 것은 불가능합니다. PoC로 보여주기 위해 샘플 프로젝트를 업로드하는 것이 좋습니다. –

+0

dev를 빌드하거나 dist 폴더의 config.json 출력을 편집 할 수 있는지 여부에 관계없이 문제가없는 GIT는 https://github.com/medeirosrich/ConfigExample입니다. 런타임에 설정이 선택됩니다. 어디에서 배포할지 선택할 수 있습니다. –