Repository navigation
Expand file tree
/
Copy pathwebpack-config.ts
More file actions
63 lines (55 loc) · 2.36 KB
/
Copy pathwebpack-config.ts
File metadata and controls
63 lines (55 loc) · 2.36 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
import { CliConfig } from './config';
import { NgCliEnvironmentPlugin } from '../utilities/environment-plugin';
import {
getWebpackCommonConfig,
getWebpackDevConfigPartial,
getWebpackProdConfigPartial,
getWebpackMobileConfigPartial,
getWebpackMobileProdConfigPartial
} from './';
const webpackMerge = require('webpack-merge');
const path = require('path');
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;
private webpackDevConfigPartial: any;
private webpackProdConfigPartial: any;
private webpackBaseConfig: any;
private webpackMaterialConfig: any;
private webpackMaterialE2EConfig: any;
private webpackMobileConfigPartial: any;
private webpackMobileProdConfigPartial: any;
constructor(public ngCliProject: any, public environment: string) {
this.webpackBaseConfig = getWebpackCommonConfig(this.ngCliProject.root);
this.webpackDevConfigPartial = getWebpackDevConfigPartial(this.ngCliProject.root);
this.webpackProdConfigPartial = getWebpackProdConfigPartial(this.ngCliProject.root);
if (CliConfig.fromProject().apps[0].mobile){
this.webpackMobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root);
this.webpackMobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root);
this.webpackBaseConfig = webpackMerge(this.webpackBaseConfig, this.webpackMobileConfigPartial);
this.webpackProdConfigPartial = webpackMerge(this.webpackProdConfigPartial, this.webpackMobileProdConfigPartial);
}
this.generateConfig();
this.config.plugins.unshift(new NgCliEnvironmentPlugin({env: this.environment}));
}
generateConfig(): void {
switch (this.environment) {
case "d":
case "dev":
case "development":
case "develop":
this.config = webpackMerge(this.webpackBaseConfig, this.webpackDevConfigPartial);
break;
case "p":
case "prod":
case "production":
this.config = webpackMerge(this.webpackBaseConfig, this.webpackProdConfigPartial);
break;
default:
//TODO: Not sure what to put here. We have a default env passed anyways.
this.ngCliProject.ui.writeLine("Envrionment could not be determined while configuring your build system.", 3)
break;
}
}
}