1
+ import * as fs from 'fs' ;
1
2
import * as path from 'path' ;
2
- import { AotPlugin } from '@ngtools/webpack' ;
3
+ import { AotPlugin , AotPluginOptions } from '@ngtools/webpack' ;
3
4
import { WebpackConfigOptions } from '../webpack-config' ;
4
5
5
6
@@ -9,6 +10,28 @@ const webpackLoader: string = g['angularCliIsLocal']
9
10
: '@ngtools/webpack' ;
10
11
11
12
13
+ function _createAotPlugin ( wco : WebpackConfigOptions , options : any ) {
14
+ const { appConfig, projectRoot, buildOptions } = wco ;
15
+
16
+ // Read the environment, and set it in the compiler host.
17
+ const appRoot = path . resolve ( projectRoot , wco . appConfig . root ) ;
18
+ const sourcePath = wco . appConfig . environments [ 'source' ] ;
19
+ const envFile = wco . appConfig . environments [ wco . buildOptions . environment ] ;
20
+ const environmentContent = fs . readFileSync ( path . join ( appRoot , envFile ) ) . toString ( ) ;
21
+
22
+ return new AotPlugin ( Object . assign ( { } , {
23
+ tsConfigPath : path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ,
24
+ mainPath : path . join ( projectRoot , appConfig . root , appConfig . main ) ,
25
+ i18nFile : buildOptions . i18nFile ,
26
+ i18nFormat : buildOptions . i18nFormat ,
27
+ locale : buildOptions . locale ,
28
+ hostOverrideFileSystem : {
29
+ [ path . join ( appRoot , sourcePath ) ] : environmentContent
30
+ }
31
+ } , options ) ) ;
32
+ }
33
+
34
+
12
35
export const getNonAotConfig = function ( wco : WebpackConfigOptions ) {
13
36
const { projectRoot, appConfig } = wco ;
14
37
let exclude = [ '**/*.spec.ts' ] ;
@@ -24,18 +47,13 @@ export const getNonAotConfig = function(wco: WebpackConfigOptions) {
24
47
]
25
48
} ,
26
49
plugins : [
27
- new AotPlugin ( {
28
- tsConfigPath : path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ,
29
- mainPath : path . join ( projectRoot , appConfig . root , appConfig . main ) ,
30
- exclude : exclude ,
31
- skipCodeGeneration : true
32
- } ) ,
50
+ _createAotPlugin ( wco , { exclude, skipCodeGeneration : true } ) ,
33
51
]
34
52
} ;
35
53
} ;
36
54
37
55
export const getAotConfig = function ( wco : WebpackConfigOptions ) {
38
- const { projectRoot, buildOptions , appConfig } = wco ;
56
+ const { projectRoot, appConfig } = wco ;
39
57
let exclude = [ '**/*.spec.ts' ] ;
40
58
if ( appConfig . test ) { exclude . push ( path . join ( projectRoot , appConfig . root , appConfig . test ) ) ; } ;
41
59
return {
@@ -49,14 +67,7 @@ export const getAotConfig = function(wco: WebpackConfigOptions) {
49
67
]
50
68
} ,
51
69
plugins : [
52
- new AotPlugin ( {
53
- tsConfigPath : path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ,
54
- mainPath : path . join ( projectRoot , appConfig . root , appConfig . main ) ,
55
- i18nFile : buildOptions . i18nFile ,
56
- i18nFormat : buildOptions . i18nFormat ,
57
- locale : buildOptions . locale ,
58
- exclude : exclude
59
- } )
70
+ _createAotPlugin ( wco , { exclude } )
60
71
]
61
72
} ;
62
73
} ;
0 commit comments