Skip to content

Commit fc1af91

Browse files
committed
Merge branch 'master' into karma-env
2 parents 3180834 + c3593c7 commit fc1af91

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

README.md

Lines changed: 14 additions & 8 deletions
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

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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
],

packages/angular-cli/models/webpack-build-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
8989
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
9090
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
9191
path.resolve(appRoot, appConfig.environments[environment])
92-
),
92+
)
9393
],
9494
tslint: {
9595
emitErrors: false,

packages/angular-cli/plugins/karma.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const getWebpackTestConfig = require('../models/webpack-build-test').getWebpackT
44
const init = (config) => {
55

66
// load Angular CLI config
7-
if (!config.angularCli && !config.angularCli.config) {
8-
throw new Error('Missing \'angularCliConfig\' entry in Karma config');
7+
if (!config.angularCli || !config.angularCli.config) {
8+
throw new Error('Missing \'angularCli.config\' entry in Karma config');
99
}
10-
const angularCliConfig = require(path.join(config.basePath, config.config.angularCli.config));
10+
const angularCliConfig = require(path.join(config.basePath, config.angularCli.config));
1111
const appConfig = angularCliConfig.apps[0];
1212
const environment = config.angularCli.environment || 'dev';
1313

0 commit comments

Comments
 (0)