-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
normalizeOptions.js
54 lines (49 loc) · 1.53 KB
/
normalizeOptions.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
'use strict';
function normalizeOptions(compiler, options) {
// Setup default value
options.serveIndex =
typeof options.serveIndex !== 'undefined' ? options.serveIndex : true;
options.contentBase =
typeof options.contentBase !== 'undefined'
? options.contentBase
: process.cwd();
options.contentBasePublicPath = options.contentBasePublicPath || '/';
options.watchOptions = options.watchOptions || {};
options.hot =
typeof options.hot === 'boolean' || options.hot === 'only'
? options.hot
: true;
options.liveReload =
typeof options.liveReload !== 'undefined' ? options.liveReload : true;
options.stats =
options.stats && Object.keys(options.stats).length !== 0
? options.stats
: {};
// normalize transportMode option
if (typeof options.transportMode === 'undefined') {
options.transportMode = {
server: 'ws',
client: 'ws',
};
} else {
switch (typeof options.transportMode) {
case 'string':
options.transportMode = {
server: options.transportMode,
client: options.transportMode,
};
break;
// if not a string, it is an object
default:
options.transportMode.server = options.transportMode.server || 'ws';
options.transportMode.client = options.transportMode.client || 'ws';
}
}
if (!options.client) {
options.client = {};
}
options.client.path = `/${
options.client.path ? options.client.path.replace(/^\/|\/$/g, '') : 'ws'
}`;
}
module.exports = normalizeOptions;