-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
140 lines (138 loc) · 3.79 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
128
129
130
131
132
133
134
135
136
137
138
139
140
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
const isDevelopment = process.env.NODE_ENV !== 'production';
const isAnalyze = !!process.env.ANALYZE;
module.exports = {
mode: isDevelopment ? 'development' : 'production',
module: {
rules: [
{
test: /\.s?css$/,
use: [
isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isDevelopment
? '[name]__[local]-[hash:base64:10]'
: '[hash:base64]',
},
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('postcss-flexbugs-fixes'),
'postcss-preset-env',
require('postcss-normalize')(),
],
},
},
},
'sass-loader',
],
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [
isDevelopment && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
},
},
{
test: /\.svg$/,
use: [
{
loader: '@svgr/webpack',
options: {
// typescript: true, // resolved in types folder
},
},
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'assets', 'index.html'),
hash: true,
}),
new CopyPlugin({
patterns: [{ from: 'public', to: 'static', noErrorOnMissing: true }],
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: {
semantic: true,
syntactic: true,
},
mode: 'write-references',
},
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
}),
isAnalyze && new BundleAnalyzerPlugin(),
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
optimization: {
minimizer: ['...', new CssMinimizerPlugin()],
splitChunks: {
cacheGroups: {
vendors: {
test: /node_modules/,
chunks: 'initial',
filename: 'vendors.[contenthash].js',
priority: 1,
maxInitialRequests: 2, // create only one vendor file
minChunks: 1,
},
},
},
},
entry: { main: path.resolve(__dirname, 'src', 'index.tsx') },
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, isDevelopment ? '.dev' : 'build'),
clean: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
plugins: [new TsconfigPathsPlugin()],
alias: {
style: path.resolve(__dirname, 'src', 'styles'), // sass partials importing fix
},
},
devServer: {
hot: isDevelopment,
port: 8888,
proxy: {
'/api': {
target: 'ws://localhost:8080',
},
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
ws: true,
},
},
historyApiFallback: true,
},
};