forked from elabftw/elabftw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.js
161 lines (160 loc) · 4.64 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
150
151
152
153
154
155
156
157
158
159
160
161
/**
* @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 path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const webpack = require('webpack');
module.exports = (env) => {
return {
entry: {
main: [
'./src/scss/main.scss',
'./src/ts/common.ts',
'./src/ts/i18n.ts',
'./src/ts/steps-links.ts',
'./src/ts/tags.ts',
'./src/ts/admin.ts',
'./src/ts/profile.ts',
'./src/ts/edit.ts',
'./src/ts/team.ts',
'./src/ts/metadata.ts',
'./src/ts/uploads.ts',
'./src/ts/todolist.ts',
'./src/ts/ucp.ts',
'./src/ts/view.ts',
'./src/ts/revisions.ts',
'./src/ts/toolbar.ts',
'./src/ts/editusers.ts',
'./src/ts/search.ts',
'./src/ts/show.ts',
'./src/ts/sysconfig.ts',
'bootstrap/js/src/alert.js',
'bootstrap/js/src/button.js',
'bootstrap/js/src/collapse.js',
'bootstrap/js/src/dropdown.js',
'./src/ts/mathjax.ts',
'prismjs',
// see list in tinymce.ts for 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-diff.js',
'prismjs/components/prism-fortran.js',
'prismjs/components/prism-go.js',
'prismjs/components/prism-java.js',
'prismjs/components/prism-javascript.js',
'prismjs/components/prism-json.js',
'prismjs/components/prism-julia.js',
'prismjs/components/prism-latex.js',
'prismjs/components/prism-lua.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',
'prismjs/components/prism-sql.js',
'prismjs/components/prism-tcl.js',
'prismjs/components/prism-vhdl.js',
'prismjs/components/prism-yaml.js',
'./src/js/vendor/keymaster.js',
],
},
// uncomment this to find where the error is coming from
// makes the build slower
//devtool: 'inline-source-map',
mode: 'production',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'web/assets')
},
optimization: {
splitChunks: {
chunks: 'all',
name: 'vendor',
},
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin(),
],
},
plugins: [
// https://webpack.js.org/plugins/define-plugin/
new webpack.DefinePlugin({
'__MAX_UPLOAD_SIZE__': JSON.stringify(env.MAX_UPLOAD_SIZE),
'__MAX_UPLOAD_TIME__': JSON.stringify(env.MAX_UPLOAD_TIME),
}),
new MiniCssExtractPlugin(
{
filename: 'vendor.min.css',
}
),
],
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules:[
{ // ts loader
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
// in prod, we don't have the types of some libs, use transpileOnly to avoid errors
transpileOnly: env.production
}
},
},
{ // CSS LOADER
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
{ // SASS loader
test: /\.scss$/,
type: 'asset/resource',
generator: {
filename: 'elabftw.min.css',
},
use: ['sass-loader'],
},
{
test: /.(jpg|jpeg|png|svg)$/,
type: 'asset/resource',
},
// expose jquery globally
{
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: ['$', 'jQuery'],
},
},
// expose key for keymaster globally
{
test: /keymaster.js/,
loader: 'expose-loader',
options: {
exposes: 'key',
},
}
]
}
}
};