-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.ts
96 lines (89 loc) · 2.19 KB
/
webpack.ts
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
require('dotenv').config();
const webpack = require("webpack");
const Dotenv = require('dotenv-webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
favicon: path.resolve(__dirname, 'public', 'favicon.ico'),
template: path.resolve(__dirname, 'public', 'index.html'),
});
const dotEnv = new Dotenv({
defaults: true,
})
const isDevelopment = process.env.NODE_ENV !== 'production';
const config = {
mode: isDevelopment ? 'development' : 'production',
entry: path.resolve(__dirname, 'src', 'index.tsx'),
output: {
publicPath: '/',
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
alias: {
'src': path.join(__dirname, 'src')
}
},
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
},
}
],
},
{
test: /\.css/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
],
},
{
test: /.*\.(gif|png|jpe?g)$/i,
type: 'asset/resource'
},
{
test: /\.svg$/,
use: ['@svgr/webpack', 'url-loader'],
type: 'javascript/auto'
},
],
},
devServer: {
static: [
{
directory: path.join(__dirname, 'public'),
},
{
directory: path.join(__dirname, 'src'),
}
],
historyApiFallback: true,
port: 3000,
},
externals: {
react: 'React',
'react-dom': 'ReactDOM'
},
plugins: [
htmlPlugin,
dotEnv,
isDevelopment && new ReactRefreshWebpackPlugin(),
].filter(Boolean),
};
export default config;