-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
90 lines (83 loc) · 2.19 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
const as_path = (subpath) => path.resolve(__dirname, subpath);
const insertEverywhere =
'./javascript_pipeline/webpack_src/insert_everywhere.ts';
module.exports = (env, argv) => {
return {
entry: {
submissions: [
'./submissions/webpack_src/submissions.ts',
insertEverywhere,
],
basic: insertEverywhere,
},
output: {
filename: '[name].bundle.js',
path: as_path('autogenerated_static'),
},
resolve: {
extensions: ['.js', '.ts', '.sass', '.scss'],
alias: yankAliasesFromTsconfig(),
},
module: {
rules: [
{
test: /\.(js|ts)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
}),
/*
* TODO: add '"globals": { "PRODUCTION": true }' to .eslintrc when eslint
* is installed
*/
new webpack.DefinePlugin({
PRODUCTION: JSON.stringify(argv.mode === 'production'),
}),
],
cache: {
/*
* Using filesystem cache can cause CI problems, e.g.
* https://github.com/webpack/webpack/issues/13291
*
* Source: https://stackoverflow.com/a/71599521/4463352
*/
type: 'filesystem',
},
};
};
function yankAliasesFromTsconfig() {
const fs = require('fs');
const tsconfig = JSON.parse(fs.readFileSync('./tsconfig.json'));
const paths = tsconfig.compilerOptions.paths;
removeSuffix = (str, suffix) => {
if (str.endsWith(suffix)) {
return str.slice(0, -suffix.length);
} else {
return str;
}
};
const result = {};
for (const [tsAlias, tsPaths] of Object.entries(paths)) {
const alias = removeSuffix(tsAlias, '/*');
const path = removeSuffix(tsPaths[0], '/*');
result[alias] = as_path(path);
}
return result;
}