forked from marudor/bahn.expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.cjs
138 lines (130 loc) · 2.71 KB
/
webpack.config.cjs
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
const path = require('node:path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const LoadablePlugin = require('@loadable/webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
require('./scripts/adjustSwcrc.cjs');
const isDev = process.env.NODE_ENV !== 'production';
const plugins = [
new LoadablePlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development',
),
}),
];
const entry = ['./src/client/entry.ts'];
const targets = require('browserslist').loadConfig({
path: __dirname,
});
const env = {
mode: 'entry',
targets: require('browserslist').loadConfig({
path: __dirname,
}),
coreJs: '3.36',
};
if (!process.env.SKIP_OLD_BROWSER) {
env.targets.push('ios 10');
}
const rules = [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(t|j)sx?$/,
use: [
{
loader: 'swc-loader',
options: {
parseMap: true,
module: {
type: 'es6',
},
env,
},
},
],
},
{
test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
];
const optimization = {};
if (isDev) {
plugins.push(
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
);
entry.push('webpack-hot-middleware/client');
} else {
optimization.minimizer = [
new TerserPlugin({
parallel: true,
extractComments: {
condition: 'all',
banner: () => '',
},
}),
];
optimization.splitChunks = {
cacheGroups: {
vendor: {
test: /[/\\]node_modules[/\\](axios|react|react-dom|react-router|react-router-dom|@mui|@emotion|downshift|date-fns)[/\\]/,
name: 'vendor',
chunks: 'all',
},
},
};
plugins.push(
new CompressionPlugin({
filename: '[path]/[base].br[query]',
test: /\.(js|css|svg)$/,
algorithm: 'brotliCompress',
compressionOptions: { level: 11 },
threshold: 0,
minRatio: 1,
}),
new CompressionPlugin({
filename: '[path]/[base].gz[query]',
test: /\.(js|css|svg)$/,
algorithm: 'gzip',
threshold: 0,
minRatio: 1,
}),
);
}
module.exports = {
optimization,
plugins,
mode: isDev ? 'development' : 'production',
devtool: isDev ? 'cheap-module-source-map' : 'source-map',
entry,
resolve: {
modules: ['node_modules'],
extensions: ['.ts', '.tsx', '.json', '.web.ts', '.js', '.jsx'],
alias: {
'lodash-es$': 'lodash',
},
},
output: {
path: path.resolve('dist/client'),
filename: 'static/[contenthash].js',
publicPath: '/',
},
module: {
rules,
},
watchOptions: {
ignored: /node_modules/,
},
experiments: {
topLevelAwait: true,
},
};