1
+ import {
2
+ getWebpackAotConfigPartial ,
3
+ getWebpackNonAotConfigPartial
4
+ } from './webpack-build-typescript' ;
1
5
const webpackMerge = require ( 'webpack-merge' ) ;
2
6
import { CliConfig } from './config' ;
3
7
import {
@@ -12,50 +16,54 @@ export class NgCliWebpackConfig {
12
16
// TODO: When webpack2 types are finished lets replace all these any types
13
17
// so this is more maintainable in the future for devs
14
18
public config : any ;
15
- private devConfigPartial : any ;
16
- private prodConfigPartial : any ;
17
- private baseConfig : any ;
18
19
19
20
constructor (
20
21
public ngCliProject : any ,
21
22
public target : string ,
22
23
public environment : string ,
23
24
outputDir ?: string ,
24
- baseHref ?: string
25
+ baseHref ?: string ,
26
+ isAoT = false
25
27
) {
26
28
const config : CliConfig = CliConfig . fromProject ( ) ;
27
29
const appConfig = config . config . apps [ 0 ] ;
28
30
29
31
appConfig . outDir = outputDir || appConfig . outDir ;
30
32
31
- this . baseConfig = getWebpackCommonConfig (
33
+ let baseConfig = getWebpackCommonConfig (
32
34
this . ngCliProject . root ,
33
35
environment ,
34
36
appConfig ,
35
37
baseHref
36
38
) ;
37
- this . devConfigPartial = getWebpackDevConfigPartial ( this . ngCliProject . root , appConfig ) ;
38
- this . prodConfigPartial = getWebpackProdConfigPartial ( this . ngCliProject . root , appConfig ) ;
39
+ let targetConfigPartial = this . getTargetConfig ( this . ngCliProject . root , appConfig ) ;
40
+ const typescriptConfigPartial = isAoT
41
+ ? getWebpackAotConfigPartial ( this . ngCliProject . root , appConfig )
42
+ : getWebpackNonAotConfigPartial ( this . ngCliProject . root , appConfig ) ;
39
43
40
44
if ( appConfig . mobile ) {
41
45
let mobileConfigPartial = getWebpackMobileConfigPartial ( this . ngCliProject . root , appConfig ) ;
42
46
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial ( this . ngCliProject . root ,
43
47
appConfig ) ;
44
- this . baseConfig = webpackMerge ( this . baseConfig , mobileConfigPartial ) ;
45
- this . prodConfigPartial = webpackMerge ( this . prodConfigPartial , mobileProdConfigPartial ) ;
48
+ baseConfig = webpackMerge ( baseConfig , mobileConfigPartial ) ;
49
+ if ( this . target == 'production' ) {
50
+ targetConfigPartial = webpackMerge ( targetConfigPartial , mobileProdConfigPartial ) ;
51
+ }
46
52
}
47
53
48
- this . generateConfig ( ) ;
54
+ this . config = webpackMerge (
55
+ baseConfig ,
56
+ targetConfigPartial ,
57
+ typescriptConfigPartial
58
+ ) ;
49
59
}
50
60
51
- generateConfig ( ) : void {
61
+ getTargetConfig ( projectRoot : string , appConfig : any ) : any {
52
62
switch ( this . target ) {
53
63
case 'development' :
54
- this . config = webpackMerge ( this . baseConfig , this . devConfigPartial ) ;
55
- break ;
64
+ return getWebpackDevConfigPartial ( projectRoot , appConfig ) ;
56
65
case 'production' :
57
- this . config = webpackMerge ( this . baseConfig , this . prodConfigPartial ) ;
58
- break ;
66
+ return getWebpackProdConfigPartial ( projectRoot , appConfig ) ;
59
67
default :
60
68
throw new Error ( "Invalid build target. Only 'development' and 'production' are available." ) ;
61
69
}
0 commit comments