-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
116 lines (111 loc) · 2.96 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
const path = require('path');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const TsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
// eslint-disable-next-line import/order
const HtmlWebpackPlugin = require('html-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';
const buildPath = path.resolve(__dirname, 'dist');
const sourcePath = path.resolve(__dirname, 'src');
const publicPath = path.resolve(__dirname, 'public');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const getSettingsForStyles = (withModules = false) => {
return [
MiniCssExtractPlugin.loader,
!withModules
? 'css-loader'
: {
loader: 'css-loader',
options: {
modules: {
localIdentName: !isProd
? '[path][name]__[local]'
: '[hash:base64]',
},
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: ['autoprefixer'],
},
},
},
'sass-loader',
];
};
module.exports = {
entry: path.resolve(sourcePath, 'index.tsx'),
output: {
path: buildPath,
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.module\.s?css$/,
use: getSettingsForStyles(true),
},
{
test: /\.s?css$/,
exclude: /\.module\.s?css$/,
use: getSettingsForStyles(),
},
{
test: /\.[tj]sx?$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(png|svg|jpg)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 10 * 1024,
},
},
},
{
test: /\.(woff2?|eot|ttf|otf)$/,
type: 'asset/resource',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(publicPath, 'index.html'),
filename: './index.html',
}),
!isProd && new ReactRefreshWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name]-[hash].css',
}),
new TsCheckerPlugin(),
].filter(Boolean),
devServer: {
host: '127.0.0.1',
port: 3000,
static: {
directory: publicPath,
},
hot: true,
historyApiFallback: true,
},
target: !isProd ? 'web' : 'browserslist',
devtool: isProd ? 'hidden-source-map' : 'eval-source-map',
resolve: {
extensions: ['.tsx', '.jsx', '.js', '.ts'],
alias: {
'@components': path.join(sourcePath, 'components/'),
'@config': path.join(sourcePath, 'config/'),
'@global': path.join(sourcePath, 'global/'),
'@mixins': path.join(sourcePath, 'mixins/'),
'@pages': path.join(sourcePath, 'pages/'),
'@store': path.join(sourcePath, 'store/'),
'@styles': path.join(sourcePath, 'styles/'),
'@entities': path.join(sourcePath, 'entities/'),
'@hooks': path.join(sourcePath, 'hooks/'),
'@utils': path.join(sourcePath, 'utils/'),
},
},
};