-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
159 lines (152 loc) · 3.64 KB
/
webpack.config.js
File metadata and controls
159 lines (152 loc) · 3.64 KB
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
const path = require('path');
const webpack = require('webpack');
const SentryPlugin = require('@sentry/webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const TerserJSPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
require('dotenv').config();
const isProduction = process.env.NODE_ENV === 'production';
const plugins = [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env), // it will automatically pick up key values from .env file
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'index.html'),
filename: 'index.html',
}),
new CopyWebpackPlugin({
patterns: [{ from: 'static', to: 'static' }, '_redirects'],
}),
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
new MiniCssExtractPlugin({
filename: isProduction ? '[name].[contenthash:8].css' : '[name].css',
chunkFilename: isProduction ? '[name].[contenthash:8].css' : '[name].bundle.css',
ignoreOrder: true,
}),
];
// enable only when you want to analyze bundles
// if (!isProduction) {
// plugins.push(new BundleAnalyzerPlugin());
// }
if (isProduction && !!process.env.SENTRY_TOKEN) {
plugins.push(
new SentryPlugin({
include: './dist',
ignore: ['node_modules', 'webpack.config.js'],
configFile: './.sentryclirc',
debug: true,
}),
);
plugins.push(
new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
);
plugins.push(
new CompressionPlugin({
filename: '[path].br[query]',
algorithm: 'brotliCompress',
test: /\.(js|css|html|svg)$/,
compressionOptions: {
level: 11,
},
threshold: 10240,
minRatio: 0.8,
}),
);
plugins.push(new HardSourceWebpackPlugin());
}
module.exports = {
entry: path.join(__dirname, 'src/index.js'),
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: isProduction ? '[name].[contenthash].js' : '[name].js',
chunkFilename: '[name].[contenthash].bundle.js',
},
plugins,
devtool: 'source-map',
optimization: {
runtimeChunk: {
name: 'manifest',
},
minimizer: [
new TerserJSPlugin({
parallel: true,
}),
new CssMinimizerPlugin(),
],
splitChunks: {
cacheGroups: {
vendor: {
idHint: 'vendor',
test: /[\\/]node_modules[\\/](react|react-dom|antd)[\\/]/,
chunks: 'all',
reuseExistingChunk: true,
},
},
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
},
},
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader' },
{
loader: 'less-loader',
options: {
javascriptEnabled: true,
modifyVars: {
'@font-family': "'Inter', sans-serif",
},
},
},
],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(ttf|eot|svg|png)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: {
loader: 'file-loader',
},
},
],
},
devServer: {
client: {
overlay: {
warnings: false,
errors: true,
},
},
},
};