-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget-webpack-config.js
86 lines (75 loc) · 2.09 KB
/
get-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
// node modules
const { merge } = require('webpack-merge');
/**
* return a webpack settings file
* @param name string
* @returns {{}}
*/
const getWebpackSettings = (name) => {
let settings = {};
try {
settings = require('./webpack-settings/' + name + '.settings.js');
} catch (e) {
// that's okay
}
return settings;
};
/**
* return a webpack settings file combined with the 'app' settings
* @param name string
* @returns {{}}
*/
const getCombinedWebpackSettings = (name) => ({
...getWebpackSettings('app'),
...getWebpackSettings(name),
});
/**
* return a legacy webpack config file
* @param name
* @returns {{}}
*/
const getLegacyWebpackConfig = (name) => require('./webpack-configs/' + name + '.config.js')('legacy', getCombinedWebpackSettings(name));
/**
* return a modern webpack config file
* @param name
* @returns {{}}
*/
const getModernWebpackConfig = (name) => require('./webpack-configs/' + name + '.config.js')('modern', getCombinedWebpackSettings(name));
/**
* return an array of webpack configs using the function provided in getWebpackConfig
* @param names string[]
* @param getWebpackConfig function
* @returns {{}}
*/
const webpackConfigs = (names, getWebpackConfig) => {
let config = {};
names.forEach((name) => config = merge(config, getWebpackConfig(name)));
return config;
};
/**
* return an array of build webpack configs
* @param names string
* @returns {{}}
*/
const buildWebpackConfigs = (...names) => webpackConfigs(names, getModernWebpackConfig);
/**
* return an array of legacy webpack configs
* @param names string
* @returns {{}}
*/
const legacyWebpackConfigs = (...names) => webpackConfigs(names, getLegacyWebpackConfig);
/**
* return an array of modern webpack configs
* @param names string
* @returns {{}}
*/
const modernWebpackConfigs = (...names) => webpackConfigs(names, getModernWebpackConfig);
// module exports
module.exports = {
getWebpackSettings,
getLegacyWebpackConfig,
getModernWebpackConfig,
buildWebpackConfigs,
legacyWebpackConfigs,
modernWebpackConfigs,
};