forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
153 lines (140 loc) · 4.51 KB
/
webpack.config.babel.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// 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.
import path from 'path';
// eslint-disable-next-line import/default
import CopyWebpackPlugin from 'copy-webpack-plugin';
import glob from 'glob';
import {minify} from 'uglify-js';
import webpack from 'webpack';
import {customizeArray, mergeWithCustomize} from 'webpack-merge';
import {
getThemeEntryPoints,
webpackDefaults,
indicoStaticLoader,
generateAssetPath,
} from './webpack';
import config from './webpack-build-config';
let entryPoints = {
jquery: ['./js/jquery/index.js'],
exports: ['./js/exports.js'],
main: ['./js/index.js'],
conferences: ['./styles/legacy/Conf_Basic.scss'],
markdown: ['./js/jquery/markdown.js'],
mathjax: ['./js/jquery/compat/mathjax.js'],
statistics: ['./js/jquery/statistics.js'],
fonts: ['./styles/partials/_fonts.scss'],
outdatedbrowser: ['./js/outdatedbrowser/index.js'],
};
const modulesDir = path.join(config.build.rootPath, '..', 'node_modules');
const extraResolveAliases = [
{name: 'jquery', alias: path.resolve(modulesDir, 'jquery/src/jquery')},
];
// Add Module Bundles
glob
.sync(path.join(config.build.rootPath, 'modules/**/module.json'))
.sort((a, b) => b.split('/').length - a.split('/').length)
.forEach(file => {
const module = {produceBundle: true, partials: {}, ...require(file)};
// eslint-disable-next-line prefer-template
const moduleName = 'module_' + (module.parent ? module.parent + '.' : '') + module.name;
const dirName = path.join(path.dirname(file), 'client/js');
if (module.produceBundle) {
entryPoints[moduleName] = [dirName];
}
const modulePath = path.join('indico/modules', module.parent || '', module.name);
extraResolveAliases.push({name: modulePath, alias: dirName, onlyModule: false});
if (module.partials) {
for (const partial of Object.entries(module.partials)) {
entryPoints[`${moduleName}.${partial[0]}`] = [path.resolve(dirName, partial[1])];
}
}
});
// This has to be last in the array, since it's the most general alias.
// Otherwise, it would be caught before 'indico/modules/...'
extraResolveAliases.push({
name: 'indico',
alias: path.join(config.build.clientPath, 'js/'),
onlyModule: false,
});
// Add Meeting Themes
entryPoints = Object.assign(entryPoints, getThemeEntryPoints(config, './themes/'));
export default env => {
const currentEnv = (env ? env.NODE_ENV : null) || 'development';
// Minification of copied files (e.g. MathJax)
const transform =
currentEnv === 'development'
? undefined
: (content, filePath) => {
if (!filePath.match(/\.js$/)) {
return content;
}
const result = minify(content.toString());
if (result.error) {
throw result.error;
}
return result.code;
};
return mergeWithCustomize({
customizeArray: customizeArray({
'resolve.alias': 'prepend',
}),
})(webpackDefaults(env, config), {
entry: entryPoints,
module: {
rules: [
{
test: /client\/js\/legacy\/libs\/.*$/,
use: 'script-loader',
},
{
test: /\.tpl\.html$/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
context: config.build.distPath,
outputPath: 'mod_assets/',
},
},
},
{
include: /jquery-migrate/,
parser: {
amd: false,
},
},
indicoStaticLoader(config),
{
test: /\/node_modules\/.*\.(jpe?g|png|gif|svg|woff2?|ttf|eot)$/,
use: {
loader: 'file-loader',
options: {
name: generateAssetPath(config),
context: config.build.distPath,
outputPath: 'mod_assets/',
publicPath: `${config.build.distURL}mod_assets/`,
},
},
},
],
},
plugins: [
new CopyWebpackPlugin({
// mathjax requests some assets dynamically after it has been loaded,
// so we copy everything to the dist folder.
patterns: [{from: path.resolve(modulesDir, 'mathjax'), to: 'js/mathjax', transform}],
}),
new webpack.ProvidePlugin({
_: ['underscore', 'default'],
moment: 'moment',
}),
],
resolve: {
alias: extraResolveAliases,
},
});
};