forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.js
149 lines (148 loc) · 4.35 KB
/
builder.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
/**
* @author Nicolas CARPi <[email protected]>
* @copyright 2012 Nicolas CARPi
* @see https://www.elabftw.net Official website
* @license AGPL-3.0
* @package elabftw
*
* Config file for webpack
*
* This is in fact webpack.config.js but I renamed it builder.js
* because I don't want any path clash with the web folder when
* doing autocompletion.
*/
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: {
main: [
'./src/ts/common.ts',
'./src/ts/steps-links.ts',
'./src/ts/tabs.ts',
'./src/ts/tags.ts',
'bootstrap/js/src/alert.js',
'bootstrap/js/src/button.js',
'bootstrap/js/src/collapse.js',
'bootstrap/js/src/dropdown.js',
'./src/ts/fontawesome.ts',
// mathjax config must be loaded before mathjax lib
'./web/app/js/src/mathjax-config.js',
// load tex with all the extensions
'mathjax/es5/tex-svg-full.js',
'prismjs',
// see list in edit.js tinymce codesample plugin settings
'prismjs/components/prism-bash.js',
'prismjs/components/prism-c.js',
'prismjs/components/prism-cpp.js',
'prismjs/components/prism-css.js',
'prismjs/components/prism-fortran.js',
'prismjs/components/prism-go.js',
'prismjs/components/prism-java.js',
'prismjs/components/prism-javascript.js',
'prismjs/components/prism-julia.js',
'prismjs/components/prism-latex.js',
'prismjs/components/prism-makefile.js',
'prismjs/components/prism-matlab.js',
'prismjs/components/prism-perl.js',
'prismjs/components/prism-python.js',
'prismjs/components/prism-r.js',
'prismjs/components/prism-ruby.js',
],
admin: './src/ts/admin.ts',
changepass: './src/ts/change-pass.ts',
edit: [
'./src/ts/edit.ts',
'./src/ts/jsoneditor.ts',
],
editusers: './src/ts/editusers.ts',
profile: './src/ts/profile.ts',
search: './src/ts/search.ts',
show: './src/ts/show.ts',
sysconfig: './src/ts/sysconfig.ts',
team: './src/ts/team.ts',
todolist: './src/ts/todolist.ts',
ucp: './src/ts/ucp.ts',
uploads: './src/ts/uploads.ts',
view: [
'./src/ts/view.ts',
'./src/ts/comments.ts',
],
},
plugins: [
// only load the moment locales that we are interested in
new webpack.ContextReplacementPlugin(/moment[\\\/]locale$/, /^\.\/(ca|de|en|es|fr|it|id|ja|kr|nl|pl|pt|pt-br|ru|sk|sl|zh-cn)$/),
// insert the paths of the bundles into the html template
// this creates a web/app/js/script-tags.html file that we can copy paste into the real html template in src/template/head.html
new HtmlWebpackPlugin({
filename: 'scripts-tags.html',
template: 'src/js/scripts-tags.html',
inject: false,
// we only want the vendors chunks
excludeChunks: ['admin', 'changepass', 'edit', 'editusers', 'profile', 'search', 'show', 'sysconfig', 'team', 'todolist', 'ucp', 'uploads', 'view'],
}),
],
mode: 'production',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'web/app/js')
},
optimization: {
splitChunks: {
chunks: 'all',
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 6,
maxInitialRequests: 4,
automaticNameDelimiter: '~',
automaticNameMaxLength: 50,
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
},
},
module: {
rules:[
// ts loader
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
},
},
// transpile things with babel so javascript works with Edge
{
test: /\.m?js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
// expose jquery and moment globally
{
test: require.resolve('jquery'),
use: [
{ loader: 'expose-loader', options: 'jQuery' },
{ loader: 'expose-loader', options: '$' },
]
},
{
test: require.resolve('moment'),
use: [
{ loader: 'expose-loader', options: 'moment' },
]
}
]
}
};