forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.webpack.config.mjs
102 lines (95 loc) · 3.24 KB
/
plugin.webpack.config.mjs
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// This file is part of Indico.
// Copyright (C) 2002 - 2024 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.
import {readFileSync} from 'node:fs';
import path from 'path';
import process from 'process';
import glob from 'glob';
import _ from 'lodash';
import {mergeWithCustomize, customizeArray} from 'webpack-merge';
const config = JSON.parse(
readFileSync(path.join(process.env.INDICO_PLUGIN_ROOT, 'webpack-build-config.json'))
);
const bundles = JSON.parse(
readFileSync(path.join(process.env.INDICO_PLUGIN_ROOT, 'webpack-bundles.json'))
);
const base = await import(path.join(config.build.indicoSourcePath, 'webpack/base.mjs'));
const entry = bundles.entry || {};
if (!_.isEmpty(config.themes)) {
const themeFiles = base.getThemeEntryPoints(config, './themes/');
Object.assign(entry, themeFiles);
}
function generateModuleAliases() {
return glob.sync(path.join(config.indico.build.rootPath, 'modules/**/module.json')).map(file => {
const mod = {produceBundle: true, partials: {}, ...JSON.parse(readFileSync(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,
};
});
}
export default env => {
return mergeWithCustomize({
customizeArray: customizeArray({
'resolve.alias': 'prepend',
}),
})(base.webpackDefaults(env, config, bundles, true), {
entry,
externals: {
'jquery': 'jQuery',
'moment': 'moment',
'react': '_IndicoCoreReact',
'react-dnd': '_IndicoCoreReactDnd',
'react-dom': '_IndicoCoreReactDom',
'react-redux': '_IndicoCoreReactRedux',
'react-router': '_IndicoCoreReactRouter',
'react-router-dom': '_IndicoCoreReactRouterDom',
'prop-types': '_IndicoCorePropTypes',
'redux': '_IndicoCoreRedux',
'semantic-ui-react': '_IndicoCoreSUIR',
'react-final-form': '_IndicoCoreReactFinalForm',
'indico/react/components': '_IndicoReactComponents',
'indico/react/components/syncedInputs': '_IndicoSyncedInputs',
'indico/react/forms': '_IndicoReactForm',
'indico/react/forms/fields': '_IndicoReactFormField',
'indico/react/i18n': '_IndicoReactI18n',
'indico/react/util': '_IndicoReactUtil',
'indico/utils/axios': '_IndicoUtilsAxios',
'indico/utils/date': '_IndicoUtilsDate',
'indico/utils/case': '_IndicoUtilsCase',
'indico/utils/plugins': '_IndicoUtilsPlugins',
'indico/react/components/principals/imperative': '_IndicoPrincipalsImperative',
},
module: {
rules: [
{
test: /.*\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/,
use: {
loader: 'file-loader',
},
},
],
},
resolve: {
alias: generateModuleAliases(),
},
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: 'common',
// exclude themes/print css from common chunk
chunks: chunk => chunk.canBeInitial() && !/\.print$|^themes_/.test(chunk.name),
minChunks: 2,
},
},
},
},
});
};