-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
74 lines (68 loc) · 2.27 KB
/
webpack.config.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
const glob = require('glob');
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
// eslint-disable-next-line global-require
const banner = '@see ' + require('./package.json').homepage;
// TODO: Look into caching to prevent the initial compilation when running `npm run watch`
// This compilation should not be needed, and may become a big nuisance when the project grows bigger
module.exports = {
mode: 'production',
watchOptions: {
ignored: /node_modules/,
},
// Allow relative imports from the project root dir using ~
resolve: {
alias: {
'~': path.resolve(__dirname),
},
},
/** Properly link a variable number of individual entry files to corresponding output files */
// Match all .mjs files separately, using useful names for `output.filename`
entry: glob.sync('./src/*/*.mjs').reduce((acc, filename) => {
// The name will be exactly what `*/*` matches in the above glob
acc[filename.slice(6, -4)] = filename;
return acc;
}, {}),
// Use the [name] reference to ensure each output file is correctly identified by its corresponding entry file
output: {
filename: './[name].js',
path: path.resolve(__dirname, 'dist'),
},
/** Use Babel to transpile to NodeJS v8.10, which is the version as supported by CSES */
target: 'node8.10',
module: {
rules: [
{
test: /\.mjs$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
configFile: path.resolve(__dirname, 'babel.config.js'),
},
},
},
],
},
/** Add repo link at the top of output files */
plugins: [
new webpack.BannerPlugin({
banner,
entryOnly: true,
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: new RegExp(banner, 'i'),
},
},
extractComments: false,
}),
],
},
};