Skip to content

refactor(build): replace source in environments with environmentDefault entry #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ By default, the development build target and environment are used.
The mapping used to determine which environment file is used can be found in `angular-cli.json`:

```json
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ By default, the development build target and environment are used.
The mapping used to determine which environment file is used can be found in `angular-cli.json`:

```json
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-cli/blueprints/ng2/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"styles.<%= styleExt %>"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
16 changes: 13 additions & 3 deletions packages/angular-cli/lib/config/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface CliConfig {
apps?: {
root?: string;
outDir?: string;
assets?: string;
assets?: string | string[];
deployUrl?: string;
index?: string;
main?: string;
Expand All @@ -23,11 +23,21 @@ export interface CliConfig {
/**
* Global styles to be included in the build.
*/
styles?: string[];
styles?: (string | {
[name: string]: any;
input?: string;
})[];
/**
* Global scripts to be included in the build.
*/
scripts?: string[];
scripts?: (string | {
[name: string]: any;
input?: string;
})[];
/**
* Source file for environment config.
*/
environmentSource?: string;
/**
* Name and corresponding file for environment config.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/angular-cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
},
"additionalProperties": false
},
"environmentSource": {
"description": "Source file for environment config.",
"type": "string",
"additionalProperties": true
},
"environments": {
"description": "Name and corresponding file for environment config.",
"type": "object",
Expand Down
7 changes: 4 additions & 3 deletions packages/angular-cli/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export function getWebpackCommonConfig(

// process environment file replacement
if (appConfig.environments) {
if (!('source' in appConfig.environments)) {
throw new SilentError(`Environment configuration does not contain "source" entry.`);
if (!appConfig.environmentSource) {
throw new SilentError(`Environment configuration
does not contain "environmentSource" entry.`);
}
if (!(environment in appConfig.environments)) {
throw new SilentError(`Environment "${environment}" does not exist.`);
Expand All @@ -113,7 +114,7 @@ export function getWebpackCommonConfig(
// This plugin is responsible for swapping the environment files.
// Since it takes a RegExp as first parameter, we need to escape the path.
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
new RegExp(path.resolve(appRoot, appConfig['environmentSource'])
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
path.resolve(appRoot, appConfig.environments[environment])
));
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-cli/models/webpack-build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
// This plugin is responsible for swapping the environment files.
// Since it takes a RegExp as first parameter, we need to escape the path.
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
new RegExp(path.resolve(appRoot, appConfig['environmentSource'])
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
path.resolve(appRoot, appConfig.environments[environment])
),
Expand Down