Angular 6에서 'ng serve'를 통해 환경을 설정하는 방법
Angular 5.2 앱을 Angular 6으로 업데이트하려고합니다. Angular 업데이트 가이드 ( angular-cli
v6 업데이트 포함)의 지침을 성공적으로 따랐 으며 이제는
ng serve --env=local
그러나 이것은 나에게 오류를 준다 :
알 수없는 옵션 : '--env'
여러 환경 ( dev/local/prod
)을 사용하는데 이것이 Angular 5.2에서 작동하는 방식입니다. Angular 6에서 환경을 설정하는 방법은 무엇입니까?
당신은 새로운 사용해야 configuration
옵션 (이 작품 ng build
과 ng serve
뿐만 아니라를)
ng serve --configuration=local
또는
ng serve -c local
angular.json
파일 을 보면 각 구성 (Aot, Optimizer, 환경 파일 등)에 대한 설정을보다 세밀하게 제어 할 수 있습니다.
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
}
환경 별 구성 관리에 대한 자세한 정보는 여기 에서 얻을 수 있습니다 .
아래의 다른 응답에서 지적했듯이 새 '환경'을 추가해야하는 경우 빌드 작업 및 필요에 따라 서브 및 테스트 작업에 새 구성을 추가해야합니다 .
새로운 환경 추가
편집 : 명확하게하려면 파일 교체를 build
섹션 에서 지정해야합니다 . 따라서 ng serve
특정 environment
파일 ( dev2 ) 과 함께 사용 하려면 먼저 build
새로운 dev2 구성 을 추가하기 위해 섹션을 수정해야 합니다
"build": {
"configurations": {
"dev2": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev2.ts"
}
/* You can add all other options here, such as aot, optimization, ... */
],
"serviceWorker": true
},
그런 다음 방금 선언 serve
한 dev2 build
구성을 가리키고 섹션을 수정하여 새 구성을 추가하십시오.
"serve":
"configurations": {
"dev2": {
"browserTarget": "projectName:build:dev2"
}
그런 다음 ng serve -c dev2
dev2 구성 파일을 사용하는을 사용할 수 있습니다
This answer seems good.
however, it lead me towards an error as it resulted with
Configuration 'xyz' could not be found in project ...
error in build.
It is requierd not only to updated build configurations, but also serve ones.
So just to leave no confusions:
--env
is not supported inangular 6
--env
got changed into--configuration
||-c
(and is now more powerful)- to manage various envs, in addition to adding new environment file, it is now required to do some changes in
angular.json
file:- add new configuration in the build
{ ... "build": "configurations": ...
property - new build configuration may contain only
fileReplacements
part, (but more options are available) - add new configuration in the serve
{ ... "serve": "configurations": ...
property - new serve configuration shall contain of
browserTarget="your-project-name:build:staging"
- add new configuration in the build
You can try: ng serve --configuration=dev/prod
To build use: ng build --prod --configuration=dev
Hope you are using a different kind of environment.
For Angular 2 - 5 refer the article Multiple Environment in angular
For Angular 6 use ng serve --configuration=dev
Note: Refer the same article for angular 6 as well. But wherever you find
--env
instead use--configuration
. That's works well for angular 6.
Use this command for Angular 6 to build
ng build --prod --configuration=dev
You can use command ng serve -c dev
for development environment ng serve -c prod
for production environment
while building also same applies. You can use ng build -c dev
for dev build
Angular no longer supports --env instead you have to use
ng serve -c dev
for development environment and,
ng serve -c prod
for production.
NOTE: -c
or --configuration
참고URL : https://stackoverflow.com/questions/50174584/how-to-set-environment-via-ng-serve-in-angular-6
'Programing' 카테고리의 다른 글
SQL Server에서 열에서 후행 공백 제거 및 업데이트 (0) | 2020.07.04 |
---|---|
파이썬 맵 및 기타 기능 도구 사용 (0) | 2020.07.04 |
Java List에서 Scala List를 얻는 방법? (0) | 2020.07.03 |
JS 클라이언트 측 Exif 방향 : JPEG 이미지 회전 및 미러링 (0) | 2020.07.03 |
iPad에서 UITableView backgroundColor가 항상 회색 (0) | 2020.07.03 |