UPDATED:
Carefully follow these steps and you are good to go :)
----------------------------------------------------------
1. Create 4 files in environment folder: (2 might there by default)
example:
environment.ts, environment.prod.ts,environment.test1.ts,environment.test2.ts
2. Use this common code for every file with slight change:
export const environment = {
production: true, //production is true for environment.prod.ts file
//for other test production is false
apiUrl: '' //base_url of each environment
};
3. Maintain a constant file where you will write all base urls.
code sample of constant.ts:
import { environment } from '../environments/environment';
let url = environment.apiUrl;
export const AppConstant = Object.freeze({
BASE_API_URL: url,
}
4. import this constant in your service or component class wherever your calling back-end.
5. In angular-cli.json:
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"test1": "environments/environment.test1.ts",
"test2": "environments/environment.test2.ts"
}
6.
ng build --env=prod
ng build --env=dev/ng build
ng build --env=test1
ng build --env=test2
7. if aot is creating problem. you can use : ng build --env=prod --no-aot
8. TO make things simple:
you can additonally add new build commands:
"scripts": {
"ng": "ng",
"start": "ng serve --env=local --no-aot",
"start:qa": "ng serve --env=dev --no-aot",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build:prod": "ng build --prod --env=prod --no-aot --output-hashing=all",
"build:dev": "ng build --prod --env=dev --no-aot --output-hashing=all",
"build:local": "ng build --env=local"
}
When you run,command is ==> npm run start OR npm run start:qa
OR==> npm run build:local or npm run build:dev, etc.
9. Hashing will solve caching isuue.
Hope it solves your problem. It works for me.
はい、私は角CLIを使用していますが、Visual Studioのビルド/ビアシステムを公開([テンプレートVS](https://marketplace.visualstudio.com/items?itemName=AndreyFo min.AngularCLIProjectTemplate))。 VSビルドのDebug \ Releaseの設定に応じて、これらのcmd行のパラメータを制御する方法を知っていますか? –
また、ツールチェインに依存していないように見えますが、プロジェクトに入れることができるいくつかの '.json'設定ファイルを使ってAngular CLIの' base-href'を制御する方法がありますか? –
いいえ、私はVSビルドにこれらを動作させる方法がわかりません。私は2人(Visual StudioとCLI)がまだよく一緒にプレイしたとは思っていませんでしたが、時間の経過と共にいくつかの改善が見られることを期待していました。 – DeborahK