-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
113 lines (106 loc) · 3.24 KB
/
webpack.config.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import path from 'path';
import DotenvPlugin from 'dotenv-webpack';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import BundleAnalyzerPlugin from 'webpack-bundle-analyzer';
import type { Configuration as WebpackConfiguration } from 'webpack';
import type { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
interface Configuration extends WebpackConfiguration {
devserver?: WebpackDevServerConfiguration;
}
type WebpackArguments = {
[key: string]: string;
};
export default (env: NodeJS.ProcessEnv, argv: WebpackArguments) => {
const isProdcution = argv.mode === 'production';
const isDevelopment = argv.mode === 'development';
const config: Configuration = {
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
// ANCHOR: '@' 경로는 삭제 예정이므로, import시 하위 폴더 alias로 import 변경
'@': path.resolve(__dirname, 'src'),
'@api': path.resolve(__dirname, 'src/api'),
'@components': path.resolve(__dirname, 'src/components'),
'@constants': path.resolve(__dirname, 'src/constants'),
'@contexts': path.resolve(__dirname, 'src/contexts'),
'@hooks': path.resolve(__dirname, 'src/hooks'),
'@pages': path.resolve(__dirname, 'src/pages'),
'@routes': path.resolve(__dirname, 'src/routes'),
'@styles': path.resolve(__dirname, 'src/styles'),
'@utils': path.resolve(__dirname, 'src/utils'),
},
},
entry: './src/index.tsx',
output: {
filename: 'static/js/[name].[contenthash:8].js',
chunkFilename: 'static/js/[name].[contenthash:8].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
clean: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.s?css$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(png|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(__dirname, 'public/index.html'),
...(isProdcution
? {
minify: {
removeComments: true,
removeRedundantAttributes: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}
: undefined),
}),
new ForkTsCheckerWebpackPlugin({
async: isDevelopment,
typescript: {
diagnosticOptions: {
syntactic: true,
},
},
}),
new DotenvPlugin({
systemvars: true,
}),
new BundleAnalyzerPlugin.BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: false,
generateStatsFile: true,
statsFilename: 'bundle-stats.json',
}),
],
devServer: {
port: 3000,
hot: true,
historyApiFallback: true,
},
optimization: {
splitChunks: {
chunks: 'all',
},
},
};
return config;
};