Skip to content

Commit

Permalink
chore(build): map dev env to environment.ts (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Sep 12, 2016
1 parent 1572270 commit c3593c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,19 @@ The build artifacts will be stored in the `dist/` directory.

### Build Targets and Environment Files

A build can specify both a build target (`development` or `production`) and an
environment file to be used with that build. By default, the development build
target is used.
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
By default, the development build target and environment are used.

At build time, `src/environments/environment.ts` will be replaced by
`src/environments/environment.NAME.ts` where `NAME` is the argument
provided to the `--environment` flag.
The mapping used to determine which environment file is used can be found in `angular-cli.json`:

```
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
```

These options also apply to the serve command. If you do not pass a value for `environment`,
it will default to `dev` for `development` and `prod` for `production`.
Expand All @@ -150,8 +156,8 @@ ng build

You can also add your own env files other than `dev` and `prod` by doing the following:
- create a `src/environments/environment.NAME.ts`
- add `{ NAME: 'src/environments/environment.NAME.ts' }` to the the `apps[0].environments` object in `angular-cli.json`
- use them by using the `--env=NAME` flag on the build/serve commands.
- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the the `apps[0].environments` object in `angular-cli.json`
- use them via the `--env=NAME` flag on the build/serve commands.

### Base tag handling in index.html

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// The file for the current environment will overwrite this one during build.
// Different environments can be found in ./environment.{dev|prod}.ts, and
// you can create your own and use it with the --env flag.
// The build system defaults to the dev environment.
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `angular-cli.json`.

export const environment = {
production: false
Expand Down
4 changes: 2 additions & 2 deletions packages/angular-cli/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"dev": "environments/environment.dev.ts"
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
Expand Down

0 comments on commit c3593c7

Please sign in to comment.