forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.webpack.config.js
97 lines (89 loc) · 3.12 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// This file is part of Indico.
// Copyright (C) 2002 - 2023 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 _ = require('lodash');
const {mergeWithCustomize, customizeArray} = require('webpack-merge');
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 || {};
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: {}, ...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 mergeWithCustomize({
customizeArray: customizeArray({
'resolve.alias': 'prepend',
}),
})(base.webpackDefaults(env, config, bundles, true), {
entry,
externals: {
'jquery': 'jQuery',
'moment': 'moment',
'react': '_IndicoCoreReact',
'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/i18n': '_IndicoReactI18n',
'indico/react/util': '_IndicoReactUtil',
'indico/utils/axios': '_IndicoUtilsAxios',
'indico/utils/date': '_IndicoUtilsDate',
'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,
},
},
},
},
});
};