forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.webpack.config.js
82 lines (75 loc) · 2.34 KB
/
plugin.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
// This file is part of Indico.
// Copyright (C) 2002 - 2019 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.
/* eslint-disable import/no-commonjs, import/unambiguous, import/newline-after-import */
/* global module:false */
const path = require('path');
const process = require('process');
const glob = require('glob');
const merge = require('webpack-merge');
const _ = require('lodash');
const config = require(path.join(process.env.INDICO_PLUGIN_ROOT, 'webpack-build-config'));
const bundles = require(path.join(process.env.INDICO_PLUGIN_ROOT, 'webpack-bundles'));
const base = require(path.join(config.build.indicoSourcePath, 'webpack'));
const entry = bundles.entry || {};
const allThemeFiles = [];
if (!_.isEmpty(config.themes)) {
const themeFiles = base.getThemeEntryPoints(config, './themes/');
Object.assign(entry, themeFiles);
allThemeFiles.push(...Object.values(themeFiles).reduce((acc, current) => acc.concat(current)));
}
function generateModuleAliases() {
return glob.sync(path.join(config.indico.build.rootPath, 'modules/**/module.json')).map(file => {
const mod = {produceBundle: true, partials: {}, ...require(file)};
const dirName = path.join(path.dirname(file), 'client/js');
const modulePath = path.join('indico/modules', mod.parent || '', mod.name);
return {
name: modulePath,
alias: dirName,
onlyModule: false,
};
});
}
module.exports = env => {
return merge.strategy({
'resolve.alias': 'prepend',
})(base.webpackDefaults(env, config, bundles), {
entry,
externals: {
jquery: 'jQuery',
},
module: {
rules: [
{
test: /.*\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/,
use: {
loader: 'file-loader',
},
},
],
},
resolve: {
alias: generateModuleAliases(),
},
output: {
jsonpFunction: 'pluginJsonp',
},
optimization: {
splitChunks: {
cacheGroups: {
common: module => {
return {
name: 'common',
chunks: 'initial',
// exclude themes, like we do in the core webpack config
minChunks: allThemeFiles.includes(module.resource) ? 9999 : 2,
};
},
},
},
},
});
};