-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (110 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserWebpackPlugin = require('terser-webpack-plugin');
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';
const config = {
mode: isProd ? 'production' : 'development',
entry: './src/index.tsx',
devtool: 'source-map',
output: {
path: path.join(__dirname, 'dist'),
filename: 'index-bundle.js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
components: path.resolve(__dirname, './src/components'),
enums: path.resolve(__dirname, './src/enums'),
pages: path.resolve(__dirname, './src/pages'),
styles: path.resolve(__dirname, './src/styles'),
assets: path.resolve(__dirname, './src/assets'),
store: path.resolve(__dirname, './src/store'),
utils: path.resolve(__dirname, './src/utils'),
types: path.resolve(__dirname, './src/types'),
hooks: path.resolve(__dirname, './src/hooks'),
errors: path.resolve(__dirname, './src/errors'),
logic: path.resolve(__dirname, './src/logic'),
app: path.resolve(__dirname, './src/app'),
router: path.resolve(__dirname, './src/router'),
__mocks__: path.resolve(__dirname, './src/__mocks__'),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: ['/node_modules/'],
use: ['babel-loader'],
},
{
test: /\.ts(x?)$/,
exclude: ['/node_modules/'],
use: ['babel-loader', 'ts-loader'],
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.js$/,
enforce: 'pre',
use: ['source-map-loader'],
},
{
test: /\.(wav|mp3)$/,
use: ['url-loader'],
},
{
test: /\.(svg)$/i,
type: 'asset',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
filename: 'index.html',
favicon: './public/favicon.ico',
manifest: './public/manifest.json',
inject: 'body',
}),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, './public/favicon.ico') },
{
from: path.resolve(__dirname, './src/assets/sounds'),
to: path.resolve(__dirname, './dist/assets/sounds'),
toType: 'dir',
},
],
}),
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.svgoMinify,
options: {
encodeOptions: {
multipass: true,
plugins: ['preset-default'],
},
},
},
}),
],
};
if (isProd) {
config.optimization = {
minimizer: [new TerserWebpackPlugin()],
};
} else {
config.devServer = {
port: 9000,
open: true,
hot: true,
compress: true,
historyApiFallback: true,
};
}
module.exports = config;