Skip to content

Commit c3593c7

Browse files
filipesilvahansl
authored andcommitted
chore(build): map dev env to environment.ts (angular#2073)
1 parent 1572270 commit c3593c7

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

README.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,19 @@ The build artifacts will be stored in the `dist/` directory.
125125

126126
### Build Targets and Environment Files
127127

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

132-
At build time, `src/environments/environment.ts` will be replaced by
133-
`src/environments/environment.NAME.ts` where `NAME` is the argument
134-
provided to the `--environment` flag.
132+
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
133+
134+
```
135+
"environments": {
136+
"source": "environments/environment.ts",
137+
"dev": "environments/environment.ts",
138+
"prod": "environments/environment.prod.ts"
139+
}
140+
```
135141

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

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

156162
### Base tag handling in index.html
157163

packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.dev.ts

-3
This file was deleted.

packages/angular-cli/blueprints/ng2/files/__path__/environments/environment.ts

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

66
export const environment = {
77
production: false

packages/angular-cli/blueprints/ng2/files/angular-cli.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"scripts": [],
2121
"environments": {
2222
"source": "environments/environment.ts",
23-
"prod": "environments/environment.prod.ts",
24-
"dev": "environments/environment.dev.ts"
23+
"dev": "environments/environment.ts",
24+
"prod": "environments/environment.prod.ts"
2525
}
2626
}
2727
],

0 commit comments

Comments
 (0)