forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack-config.ts
More file actions
85 lines (77 loc) · 2.76 KB
/
webpack-config.ts
File metadata and controls
85 lines (77 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {
getWebpackAotConfigPartial,
getWebpackNonAotConfigPartial
} from './webpack-build-typescript';
const webpackMerge = require('webpack-merge');
import { CliConfig } from './config';
import { getWebpackCommonConfig } from './webpack-build-common';
import { getWebpackDevConfigPartial } from './webpack-build-development';
import { getWebpackProdConfigPartial } from './webpack-build-production';
import {
getWebpackMobileConfigPartial,
getWebpackMobileProdConfigPartial
} from './webpack-build-mobile';
export class NgCliWebpackConfig {
// TODO: When webpack2 types are finished lets replace all these any types
// so this is more maintainable in the future for devs
public config: any;
constructor(
public ngCliProject: any,
public target: string,
public environment: string,
outputDir?: string,
baseHref?: string,
i18nFile?: string,
i18nFormat?: string,
locale?: string,
isAoT = false,
sourcemap = true,
vendorChunk = false,
verbose = false,
progress = true
) {
const config: CliConfig = CliConfig.fromProject();
const appConfig = config.config.apps[0];
appConfig.outDir = outputDir || appConfig.outDir;
let baseConfig = getWebpackCommonConfig(
this.ngCliProject.root,
environment,
appConfig,
baseHref,
sourcemap,
vendorChunk,
verbose,
progress
);
let targetConfigPartial = this.getTargetConfig(
this.ngCliProject.root, appConfig, sourcemap, verbose
);
const typescriptConfigPartial = isAoT
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig, i18nFile, i18nFormat, locale)
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
if (appConfig.mobile) {
let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig);
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root,
appConfig);
baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
if (this.target == 'production') {
targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
}
}
this.config = webpackMerge(
baseConfig,
targetConfigPartial,
typescriptConfigPartial
);
}
getTargetConfig(projectRoot: string, appConfig: any, sourcemap: boolean, verbose: boolean): any {
switch (this.target) {
case 'development':
return getWebpackDevConfigPartial(projectRoot, appConfig);
case 'production':
return getWebpackProdConfigPartial(projectRoot, appConfig, sourcemap, verbose);
default:
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
}
}
}