forked from indico/indico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
145 lines (132 loc) · 5.32 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
/* This file is part of Indico.
* Copyright (C) 2002 - 2018 European Organization for Nuclear Research (CERN).
*
* Indico is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Indico is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Indico; if not, see <http://www.gnu.org/licenses/>.
*/
import path from 'path';
import glob from 'glob';
import merge from 'webpack-merge';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import {minify} from 'uglify-js';
import webpack from 'webpack';
import {getThemeEntryPoints, webpackDefaults, indicoStaticLoader, generateAssetPath} from './webpack';
import config from './webpack-build-config';
let entryPoints = {
main: ['./js/index.js'],
ckeditor: ['./js/jquery/ckeditor.js'],
conferences: ['./styles/legacy/Conf_Basic.css'],
map_of_rooms: ['./styles/legacy/mapofrooms.css'],
markdown: ['./js/jquery/markdown.js'],
mathjax: ['./js/jquery/compat/mathjax.js'],
statistics: ['./js/jquery/statistics.js'],
fonts: ['./styles/partials/_fonts.scss']
};
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')).forEach((file) => {
const module = Object.assign({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. CKEditor and MathJax)
const transform = currentEnv === 'development' ? null : (content, filePath) => {
if (!filePath.match(/\.js$/)) {
return content;
}
const result = minify(content.toString());
if (result.error) {
throw result.error;
}
return result.code;
};
return merge.strategy({
// resolve module aliases first, since the ones
// in base.js are more general
'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([
{from: path.resolve(modulesDir, 'ckeditor/dev/builder/release/ckeditor'), to: 'js/ckeditor', transform},
{from: path.resolve(modulesDir, 'mathjax'), to: 'js/mathjax', transform}
]),
new webpack.ProvidePlugin({
_: 'underscore',
moment: 'moment'
})
],
resolve: {
alias: extraResolveAliases
}
});
};