forked from marudor/bahn.expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
127 lines (121 loc) · 3.01 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
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
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const LoadablePlugin = require('@loadable/webpack-plugin');
const PacktrackerPlugin = require('@packtracker/webpack-plugin');
const isDev = process.env.NODE_ENV !== 'production';
const plugins = [
new PacktrackerPlugin({
fail_build: true,
upload: process.env.sendStats === 'true',
}),
new LoadablePlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'global.PROD': JSON.stringify(!isDev),
'global.TEST': JSON.stringify(process.env.NODE_ENV === 'test'),
'global.SERVER': JSON.stringify(false),
}),
];
const rules = [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(t|j)sx?$/,
use: [
{
loader: 'babel-loader',
options: {
configFile: false,
},
},
],
},
{
test: /\.(jpg|jpeg|png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
];
const optimization = {};
if (isDev) {
if (process.env.BABEL_ENV !== 'testProduction') {
rules[0].use.unshift('cache-loader');
}
} else {
optimization.minimizer = [
new TerserPlugin({
parallel: true,
extractComments: {
condition: 'all',
banner: () => '',
},
}),
];
// optimization.splitChunks = {
// minSize: 30000,
// cacheGroups: {
// vendor: {
// test: /[\\/]node_modules[\\/](react|react-dom|react-router|core-js|@material-ui)[\\/]/,
// name: 'vendor',
// chunks: 'all',
// },
// },
// };
plugins.push(
...[
new CompressionPlugin({
filename: '[path].br[query]',
test: /\.(js|css|svg)$/,
algorithm: 'brotliCompress',
compressionOptions: { level: 11 },
threshold: 0,
minRatio: 1,
}),
new CompressionPlugin({
filename: '[path].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' : false,
entry: ['./src/client/entry.ts'],
resolve: {
// plugins: [new ReactJssHmrPlugin()],
modules: ['node_modules', path.resolve(__dirname, 'src')],
extensions: ['.js', '.json', '.web.ts', '.jsx', '.ts', '.tsx'],
alias: {
classnames$: 'clsx',
'lodash-es$': 'lodash',
Abfahrten: 'client/Abfahrten',
Routing: 'client/Routing',
Common: 'client/Common',
testHelper$: '../test/client/testHelper',
},
},
output: {
path: path.resolve(
process.env.BABEL_ENV === 'testProduction'
? 'testDist/client'
: 'dist/client'
),
filename: isDev ? 'static/[name].[hash].js' : 'static/[contenthash].js',
publicPath: '/',
},
module: {
rules,
},
};