Skip to content

Commit 86ee43b

Browse files
refactor(build): replace source in environments with environmentDefault entry
Replace source in environments with separate environmentDefault entry and updated docs to reflect this change BREAKING CHANGE: angular-cli.json has changed. A new environmentDefault entry replaces the previous source entry inside environments. To migrate the code follow the example below: Before: "environments": { "source": "environments/environment.ts", "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } After: "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } Closes angular#3857
1 parent cbab6f8 commit 86ee43b

File tree

6 files changed

+13
-7
lines changed

6 files changed

+13
-7
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ By default, the development build target and environment are used.
144144
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
145145

146146
```json
147+
"environmentSource": "environments/environment.ts",
147148
"environments": {
148-
"source": "environments/environment.ts",
149149
"dev": "environments/environment.ts",
150150
"prod": "environments/environment.prod.ts"
151151
}
152+
152153
```
153154

154155
These options also apply to the serve command. If you do not pass a value for `environment`,

docs/documentation/overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ By default, the development build target and environment are used.
2929
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
3030

3131
```json
32+
"environmentSource": "environments/environment.ts",
3233
"environments": {
33-
"source": "environments/environment.ts",
3434
"dev": "environments/environment.ts",
3535
"prod": "environments/environment.prod.ts"
3636
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"styles.<%= styleExt %>"
2222
],
2323
"scripts": [],
24+
"environmentSource": "environments/environment.ts",
2425
"environments": {
25-
"source": "environments/environment.ts",
2626
"dev": "environments/environment.ts",
2727
"prod": "environments/environment.prod.ts"
2828
}

packages/@angular/cli/lib/config/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
},
132132
"additionalProperties": false
133133
},
134+
"environmentSource": {
135+
"description": "Source file for environment config.",
136+
"type": "string",
137+
"additionalProperties": true
138+
},
134139
"environments": {
135140
"description": "Name and corresponding file for environment config.",
136141
"type": "object",

packages/@angular/cli/models/webpack-configs/common.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
7373

7474
// process environment file replacement
7575
if (appConfig.environments) {
76-
if (!('source' in appConfig.environments)) {
77-
throw new SilentError(`Environment configuration does not contain "source" entry.`);
76+
if (!('source' in appConfig.environmentSource)) {
77+
throw new SilentError(`Environment configuration does not contain "environmentSource" entry.`);
7878
}
7979
if (!(buildOptions.environment in appConfig.environments)) {
8080
throw new SilentError(`Environment "${buildOptions.environment}" does not exist.`);
@@ -84,7 +84,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
8484
// This plugin is responsible for swapping the environment files.
8585
// Since it takes a RegExp as first parameter, we need to escape the path.
8686
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
87-
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
87+
new RegExp(path.resolve(appRoot, appConfig['environmentSource'])
8888
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
8989
path.resolve(appRoot, appConfig.environments[buildOptions.environment])
9090
));

packages/@angular/cli/models/webpack-configs/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const getTestConfig = function (projectRoot, environment, appConfig, testConfig)
104104
// This plugin is responsible for swapping the environment files.
105105
// Since it takes a RegExp as first parameter, we need to escape the path.
106106
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
107-
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
107+
new RegExp(path.resolve(appRoot, appConfig['source'])
108108
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
109109
path.resolve(appRoot, appConfig.environments[environment])
110110
),

0 commit comments

Comments
 (0)