Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (73 loc) · 2.19 KB
/
Copy pathwebpack.config.js
File metadata and controls
77 lines (73 loc) · 2.19 KB
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
const path = require('node:path');
const webpack = require('webpack');
// Use WEBPACK_PRODUCTION=1 to build in production mode (minified, no source maps).
// NODE_ENV is intentionally not used here because setting it to 'production' also
// triggers app config validation (ETHERPAD_PAD_URI etc.) which is unavailable at build time.
const isDev = !process.env.WEBPACK_PRODUCTION;
const minimize = !isDev;
const plugins = [
// By default, moment loads aaaall the locale files, which bloats the bundle size
// This plugin forces moment to only load the German locale
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /de/),
];
const isEditorCss = (filePath) => filePath.endsWith('.css') && filePath.includes('@hpi-schul-cloud/ckeditor');
module.exports = {
mode: isDev ? 'development' : 'production',
cache: isDev ? { type: 'filesystem' } : false,
module: {
rules: [
// Application source + htmlparser2 need transpilation.
// Everything else in node_modules is already compiled.
{
test: /\.(?:js|jsx|cjs)$/,
include: [
path.resolve(__dirname, 'static/scripts'),
path.resolve(__dirname, 'static/vendor'),
/htmlparser2/,
],
loader: 'babel-loader',
options: {
sourceType: 'unambiguous',
presets: [['@babel/preset-env', { modules: false }]],
plugins: [
'@babel/plugin-transform-react-jsx',
'@babel/plugin-transform-runtime',
],
},
},
// Styles from the shared CKEditor package (handles both npm installs and local file: symlinks).
{
test: isEditorCss,
use: ['style-loader', 'css-loader'],
},
// moment needs to be globally exposed in order to work with fullcalendar
{
test: require.resolve('moment'),
loader: 'expose-loader',
options: { exposes: [{ globalName: 'moment', override: true }] },
},
],
},
optimization: {
minimize,
splitChunks: {
cacheGroups: {
// Bundle react & react-dom into separate vendor-react bundle
react: {
test: /[\\/]node_modules[\\/](react-dom|react)[\\/]/,
name: 'vendor-react',
chunks: 'all',
},
},
},
},
externals: {
jquery: 'jQuery',
'jquery-mousewheel': 'jQuery',
},
output: {
path: '/',
filename: '[name].js',
},
plugins,
};