1
1
import * as fs from 'fs' ;
2
2
import * as path from 'path' ;
3
+ import { stripIndent } from 'common-tags' ;
3
4
import { AotPlugin , AotPluginOptions } from '@ngtools/webpack' ;
4
5
import { WebpackConfigOptions } from '../webpack-config' ;
5
6
@@ -16,22 +17,51 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
16
17
const { appConfig, projectRoot, buildOptions } = wco ;
17
18
18
19
// Read the environment, and set it in the compiler host.
19
- let hostOverrideFileSystem : any = { } ;
20
+ let hostReplacementPaths : any = { } ;
20
21
// process environment file replacement
21
22
if ( appConfig . environments ) {
22
- if ( ! ( 'source' in appConfig . environments ) ) {
23
- throw new SilentError ( `Environment configuration does not contain "source" entry.` ) ;
23
+ if ( ! appConfig . environmentSource ) {
24
+ let migrationMessage = '' ;
25
+ if ( 'source' in appConfig . environments ) {
26
+ migrationMessage = '\n\n' + stripIndent `
27
+ A new environmentSource entry replaces the previous source entry inside environments.
28
+
29
+ To migrate angular-cli.json follow the example below:
30
+
31
+ Before:
32
+
33
+ "environments": {
34
+ "source": "environments/environment.ts",
35
+ "dev": "environments/environment.ts",
36
+ "prod": "environments/environment.prod.ts"
37
+ }
38
+
39
+
40
+ After:
41
+
42
+ "environmentSource": "environments/environment.ts",
43
+ "environments": {
44
+ "dev": "environments/environment.ts",
45
+ "prod": "environments/environment.prod.ts"
46
+ }
47
+ ` ;
48
+ }
49
+ throw new SilentError (
50
+ `Environment configuration does not contain "environmentSource" entry.${ migrationMessage } `
51
+ ) ;
52
+
24
53
}
25
54
if ( ! ( buildOptions . environment in appConfig . environments ) ) {
26
55
throw new SilentError ( `Environment "${ buildOptions . environment } " does not exist.` ) ;
27
56
}
28
57
29
58
const appRoot = path . resolve ( projectRoot , appConfig . root ) ;
30
- const sourcePath = appConfig . environments [ 'source' ] ;
59
+ const sourcePath = appConfig . environmentSource ;
31
60
const envFile = appConfig . environments [ buildOptions . environment ] ;
32
- const environmentContent = fs . readFileSync ( path . join ( appRoot , envFile ) ) . toString ( ) ;
33
61
34
- hostOverrideFileSystem = { [ path . join ( appRoot , sourcePath ) ] : environmentContent } ;
62
+ hostReplacementPaths = {
63
+ [ path . join ( appRoot , sourcePath ) ] : path . join ( appRoot , envFile )
64
+ } ;
35
65
}
36
66
37
67
return new AotPlugin ( Object . assign ( { } , {
@@ -40,15 +70,18 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) {
40
70
i18nFile : buildOptions . i18nFile ,
41
71
i18nFormat : buildOptions . i18nFormat ,
42
72
locale : buildOptions . locale ,
43
- hostOverrideFileSystem
73
+ hostReplacementPaths
44
74
} , options ) ) ;
45
75
}
46
76
47
77
48
78
export const getNonAotConfig = function ( wco : WebpackConfigOptions ) {
49
79
const { projectRoot, appConfig } = wco ;
50
80
let exclude = [ '**/*.spec.ts' ] ;
51
- if ( appConfig . test ) { exclude . push ( path . join ( projectRoot , appConfig . root , appConfig . test ) ) ; } ;
81
+ if ( appConfig . test ) {
82
+ exclude . push ( path . join ( projectRoot , appConfig . root , appConfig . test ) ) ;
83
+ }
84
+
52
85
return {
53
86
module : {
54
87
rules : [
0 commit comments