forked from Graylog2/graylog2-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.combined.config.js
57 lines (43 loc) · 1.8 KB
/
webpack.combined.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
const glob = require('glob');
const path = require('path');
const merge = require('webpack-merge');
const TARGET = process.env.npm_lifecycle_event;
const pluginConfigPattern = 'graylog-plugin-*/**/webpack.config.js';
const globCwd = '../..';
const globOptions = {
ignore: '**/node_modules/**',
cwd: globCwd,
nodir: true,
};
function isNotDependency(pluginConfig) {
// Avoid including webpack configs of dependencies and built files.
return !pluginConfig.includes('/target/') && !pluginConfig.includes('/node_modules/');
}
const pluginConfigs = process.env.disable_plugins === 'true' ? [] : glob.sync(pluginConfigPattern, globOptions)
.map((config) => `${globCwd}/${config}`)
.filter(isNotDependency);
process.env.web_src_path = path.resolve(__dirname);
// eslint-disable-next-line import/no-dynamic-require
const webpackConfig = require(path.resolve(__dirname, './webpack.config.js'));
const mergedPluginConfigs = pluginConfigs
// eslint-disable-next-line global-require,import/no-dynamic-require
.map((configFile) => require(configFile))
.reduce((config, pluginConfig) => merge.smart(config, pluginConfig), {});
const finalConfig = merge.smart(mergedPluginConfigs, webpackConfig);
// We need to inject webpack-hot-middleware to all entries, ensuring the app is able to reload on changes.
if (TARGET === 'start') {
const hmrEntries = {};
const webpackHotMiddlewareEntry = 'webpack-hot-middleware/client?reload=true';
Object.keys(finalConfig.entry).forEach((entryKey) => {
const entryValue = finalConfig.entry[entryKey];
const hmrValue = [webpackHotMiddlewareEntry];
if (Array.isArray(entryValue)) {
hmrValue.push(...entryValue);
} else {
hmrValue.push(entryValue);
}
hmrEntries[entryKey] = hmrValue;
});
finalConfig.entry = hmrEntries;
}
module.exports = finalConfig;