-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebpack.config.js
82 lines (72 loc) · 1.71 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
'use strict';
/**
* Webpack Development Boilerplate
* Include:
* - stylus
* - pug
* - modular components
* - chunkhashing
* - autoprefixier
* - separated ENV
* - build system
* - etc...
* @author Mike Chernobrov
* @see http://rambler-co.ru
*/
/**
* Exported evnironments object
* @type {Object}
*/
const _configs = {
// global section
global: require(__dirname + '/config/webpack/global'),
// config by enviroments
production: require(__dirname + '/config/webpack/environments/production'),
development: require(__dirname + '/config/webpack/environments/development')
};
/**
* Load webpack config via enviroments
* @param {[type]} enviroment [description]
* @return {[type]} [description]
*/
const _load = function() {
var ENV = process.env.NODE_ENV
? process.env.NODE_ENV
: 'production';
return mergeDeep(
_configs[ENV](__dirname),
_configs.global(__dirname)
);
};
/**
* Simple is object check.
* @param {Object} item
* @return {boolean}
*/
const isObject = item => {
return (item && typeof item === 'object' && !Array.isArray(item) && item !== null);
};
/**
* Deep merge two objects.
* @param {object} target [description]
* @param {object} source [description]
* @return {object} [description]
*/
const mergeDeep = (target, source) => {
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
} else {
Object.assign(target, { [key]: source[key] });
}
}
}
return target;
};
/**
* Export WebPack config
* @type {[type]}
*/
module.exports = _load();