-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathwebpack.config.js
292 lines (268 loc) · 6.18 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
const webpack = require('webpack');
const fs = require('fs');
const path = require('path');
const constants = require('./constants');
const DefinePlugin = webpack.DefinePlugin;
const DllPlugin = webpack.DllPlugin;
const DllReferencePlugin = webpack.DllReferencePlugin;
const ROOT_DIR = constants.ROOT_DIR;
const SRC_DIR = constants.SRC_DIR;
const PUBLIC_DIR = constants.PUBLIC_DIR;
const PRIVATE_DIR = constants.PRIVATE_DIR;
const VENDOR_NAME = constants.VENDOR_NAME;
const SERVER_NAME = constants.SERVER_NAME;
const BROWSER_NAME = constants.BROWSER_NAME;
const WORKER_NAME = constants.WORKER_NAME;
const WORKER_APP_NAME = constants.WORKER_APP_NAME;
const SERVER_SOURCE_PATH = constants.SERVER_SOURCE_PATH;
const BROWSER_SOURCE_PATH = constants.BROWSER_SOURCE_PATH;
const WORKER_SOURCE_PATH = constants.WORKER_SOURCE_PATH;
const WORKER_APP_SOURCE_PATH = constants.WORKER_APP_SOURCE_PATH;
const VENDOR_DLL_MANIFEST_FILE = constants.VENDOR_DLL_MANIFEST_FILE;
const VENDOR_DLL_MANIFEST_PATH = constants.VENDOR_DLL_MANIFEST_PATH;
const NODE_MODULES = fs.readdirSync(ROOT_DIR + '/node_modules').filter(function(name) {
return name != '.bin';
});
const STATS_OPTIONS = {
colors: {
level: 2,
hasBasic: true,
has256: true,
has16m: false
},
cached: false,
cachedAssets: false,
modules: true,
chunks: false,
reasons: true,
errorDetails: true,
chunkOrigins: false,
exclude: ['node_modules']
};
const WATCH_OPTIONS = {
aggregateTimeout: 100,
poll: undefined
};
const DEV_OPTIONS = {
contentBase: false,
queit: false,
noInfo: false,
stats: STATS_OPTIONS
};
const LOADERS = [{
test: /\.ts$/,
loader: 'ts',
query: {
ignoreDiagnostics: [
2403, // 2403 -> Subsequent variable declarations
2300, // 2300 -> Duplicate identifier
2374, // 2374 -> Duplicate number index signature
2375, // 2375 -> Duplicate string index signature,
2435,
2436,
2502
]
},
exclude: [
/node_modules/
]
}, {
test: /\.html$/,
loader: 'raw'
}, {
test: /\.css$/,
loaders: ['raw', 'postcss']
}, {
test: /\.json$/,
loader: 'json'
}];
const POSTCSS = function() {
return [
require('postcss-cssnext')
]
}
const DEFINE_CONSTANTS_PLUGIN = new DefinePlugin((function stringifyConstants() {
const stringifiedConstants = {};
Object.keys(constants).forEach(function(constantName) {
stringifiedConstants[constantName] = JSON.stringify(constants[constantName]);
});
return stringifiedConstants;
})());
const VENDOR_DLL_REFERENCE_PLUGIN = new DllReferencePlugin({
context: ROOT_DIR,
sourceType: 'var',
get manifest() {
return require(VENDOR_DLL_MANIFEST_PATH);
}
});
const VENDOR_CONFIG = {
target: 'web',
entry: {
[VENDOR_NAME]: [
'core-js/es6/symbol',
'core-js/es6/object',
'core-js/es6/function',
'core-js/es6/parse-int',
'core-js/es6/parse-float',
'core-js/es6/number',
'core-js/es6/math',
'core-js/es6/string',
'core-js/es6/date',
'core-js/es6/array',
'core-js/es6/regexp',
'core-js/es6/map',
'core-js/es6/set',
'core-js/es6/weak-map',
'core-js/es6/weak-set',
'core-js/es6/typed',
'core-js/es6/reflect',
'core-js/es7/reflect',
'zone.js/dist/zone',
'zone.js/dist/long-stack-trace-zone',
'@angular/core',
'@angular/common',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/http',
]
},
output: {
path: PUBLIC_DIR,
filename: '[name].js',
library: VENDOR_NAME,
libraryTarget: 'var'
},
plugins: [
new DllPlugin({
name: VENDOR_NAME,
path: VENDOR_DLL_MANIFEST_PATH
})
]
};
const BROWSER_CONFIG = {
target: 'web',
entry: {
[BROWSER_NAME]: [
BROWSER_SOURCE_PATH
]
},
output: {
path: PUBLIC_DIR,
filename: '[name].js',
chunkFilename: '[id].' + BROWSER_NAME + '.js',
},
plugins: [
VENDOR_DLL_REFERENCE_PLUGIN
],
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: LOADERS
},
postcss: POSTCSS
};
const WORKER_CONFIG = {
target: 'web',
entry: {
[WORKER_NAME]: [
WORKER_SOURCE_PATH
]
},
output: {
path: PUBLIC_DIR,
filename: '[name].js',
chunkFilename: '[id].' + WORKER_NAME + '.js',
},
plugins: [
VENDOR_DLL_REFERENCE_PLUGIN,
DEFINE_CONSTANTS_PLUGIN,
],
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: LOADERS
},
postcss: POSTCSS
};
const WORKER_APP_CONFIG = {
target: 'webworker',
entry: {
[WORKER_APP_NAME]: [
WORKER_APP_SOURCE_PATH
]
},
output: {
path: PUBLIC_DIR,
filename: '[name].js',
chunkFilename: '[id].' + WORKER_APP_NAME + '.js'
},
get plugins() {
return [
VENDOR_DLL_REFERENCE_PLUGIN,
DEFINE_CONSTANTS_PLUGIN,
];
} ,
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: LOADERS
},
postcss: POSTCSS
};
const SERVER_CONFIG = {
target: 'node',
entry: {
[SERVER_NAME]: [
SERVER_SOURCE_PATH
]
},
output: {
path: PRIVATE_DIR,
filename: '[name].js',
chunkFilename: '[id].' + SERVER_NAME + '.js',
library: SERVER_NAME,
libraryTarget: 'commonjs2'
},
plugins: [
DEFINE_CONSTANTS_PLUGIN
],
node: {
__dirname: true,
__filename: true
},
externals: [
NODE_MODULES.map(function(name) { return new RegExp('^' + name) }),
],
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: LOADERS
},
postcss: POSTCSS
};
const TESTING_CONFIG = {
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: LOADERS
},
devServer: {
quiet: true,
noInfo: true,
}
};
exports = module.exports = [VENDOR_CONFIG, BROWSER_CONFIG, WORKER_CONFIG, WORKER_APP_CONFIG, SERVER_CONFIG];
exports.VENDOR_CONFIG = VENDOR_CONFIG;
exports.SERVER_CONFIG = SERVER_CONFIG;
exports.BROWSER_CONFIG = BROWSER_CONFIG;
exports.WORKER_CONFIG = WORKER_CONFIG;
exports.WORKER_APP_CONFIG = WORKER_APP_CONFIG;
exports.TESTING_CONFIG = TESTING_CONFIG;
exports.STATS_OPTIONS = STATS_OPTIONS;
exports.WATCH_OPTIONS = WATCH_OPTIONS;
exports.DEV_OPTIONS = DEV_OPTIONS;