This repository has been archived by the owner on Apr 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
148 lines (126 loc) · 3.05 KB
/
webpack.config.js
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
var webpack = require('webpack');
var deepExtend = require('deep-extend');
var fs = require('fs');
var path = require('path');
var exclude = /node_modules/;
var packageJsonString = fs.readFileSync('package.json', 'utf8');
var packageJson = JSON.parse(packageJsonString);
console.log('building version', packageJson.version);
var baseEnvVars = {
ON_DEV: false,
ON_TEST: false,
ON_PROD: false,
VERSION: JSON.stringify(packageJson.version)
};
var baseConfig = {
context: here('src'),
entry: './index.js',
output: {
filename: 'angular-formly-templates-foundation.js',
path: here('dist'),
library: 'ngFormlyTemplatesFoundation',
libraryTarget: 'umd'
},
stats: {
colors: true,
reasons: true
},
externals: {
angular: 'angular',
'angular-formly': {
root: 'ngFormly',
amd: 'angular-formly',
commonjs2: 'angular-formly',
commonjs: 'angular-formly'
},
'api-check': {
root: 'apiCheck',
amd: 'api-check',
commonjs2: 'api-check',
commonjs: 'api-check'
}
},
plugins: [],
resolve: {
extensions: ['', '.js'],
alias: {
'angular-fix': here('src/angular-fix')
}
},
module: {
loaders: [
{test: /\.html$/, loader: 'raw', exclude: exclude},
{test: /\.js$/, loader: 'ng-annotate!babel!jshint', exclude: exclude}
]
}
};
var devConfig = {
devtool: 'inline-source-map'
};
var prodConfig = {
output: {
filename: 'angular-formly-templates-foundation.min.js',
path: here('dist')
},
devtool: 'source-map',
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.UglifyJsPlugin({
exclude: /\.test\.js$/,
compress: {
warnings: false
}
})
],
jshint: {
failOnHint: true,
emitErrors: true
}
};
var testCIConfig = deepExtend({}, prodConfig);
var testConfig = deepExtend({}, devConfig);
delete testConfig.jshint;
delete testCIConfig.jshint;
var envContexts = {
dev: {
ON_DEV: true
},
prod: {
ON_PROD: true
},
test: {
ON_TEST: true
},
'test:ci': {
ON_TEST: true
}
};
module.exports = getConfig();
module.exports.getConfig = getConfig;
function getConfig(context) {
context = context || 'dev';
var configContexts = {
dev: devConfig,
prod: prodConfig,
test: testConfig,
'test:ci': testCIConfig
};
var resultConfig = deepExtend({}, baseConfig, configContexts[context]);
var resultVars = deepExtend({}, baseEnvVars, envContexts[context]);
resultConfig.plugins.push(new webpack.DefinePlugin(resultVars));
resultConfig.plugins.push(new webpack.BannerPlugin(getBanner(), {raw: true}));
console.log('Webpack config is in ' + context + ' mode');
return resultConfig;
}
function getBanner() {
return '// ' + packageJson.name + ' version ' +
packageJson.version +
' built with ♥ by ' +
packageJson.contributors.join(', ') +
' (ó ì_í)=óò=(ì_í ò)\n';
}
function here(p) {
return path.join(__dirname, p || '');
}