-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.common.js
175 lines (173 loc) · 4.86 KB
/
webpack.common.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const path = require("path");
const webpack = require("webpack");
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
const dotenv = require("dotenv");
const {
input,
} = require("@testing-library/user-event/dist/cjs/event/input.js");
const { createWebPGenerator } = require("./webpackUtil");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = (env) => {
const { DEV } = env;
if (DEV === "true") {
dotenv.config({ path: "./.env.dev" });
} else if (DEV === "false") {
dotenv.config({ path: "./.env.prod" });
console.log("process.env.RANDOM_URL");
}
return {
entry: "./src/client/index.tsx",
output: {
filename: "[name]-bundle.js",
path: path.resolve(__dirname, "build"),
publicPath: "/",
clean: true,
},
module: {
rules: [
{ test: /\.tsx?/, use: ["babel-loader"] },
{
test: /\.(js|jsx)$/,
exclude: "/node_modules",
use: ["babel-loader"],
},
{
test: /\.html$/,
use: [
{
loader: "html-loader",
options: { minimize: true },
},
],
},
{
test: /\.css?$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader"],
},
{
test: /\.svg$/,
use: {
loader: "@svgr/webpack",
},
},
{
test: /\.(png|jpe?g|gif|mp4|webp)$/i,
type: "asset/resource",
generator: {
filename: "assets/[name][ext]",
},
},
],
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
compress: {
drop_console: true,
drop_debugger: true,
dead_code: true,
unused: true,
reduce_vars: true,
collapse_vars: true,
evaluate: true,
booleans: true,
conditionals: true,
sequences: true,
properties: true,
hoist_funs: true,
hoist_vars: true,
passes: 2,
inline: true,
},
mangle: true,
toplevel: true,
keep_classnames: undefined,
keep_fnames: false,
},
extractComments: false,
}),
new ImageMinimizerPlugin({
minimizer: {
implementation: ImageMinimizerPlugin.sharpMinify,
options: {
encodeOptions: {
webp: {},
png: {},
},
},
},
generator: [
createWebPGenerator({ presetName: "webp", quality: 75 }),
createWebPGenerator({
presetName: "webp-high",
quality: 50,
fileNames: ["OutsideInfo.png"],
}),
createWebPGenerator({
presetName: "webp-smallh",
quality: 100,
fileNames: [
"e1Gift.png",
"Drive1.png",
"Drive2.png",
"Drive3.png",
"Drive4.png",
"Drive5.png",
"Drive6.png",
"whiteRight.png",
],
resizeOptions: {
width: 600,
height: 340,
},
}),
createWebPGenerator({
presetName: "webp-smallw",
quality: 75,
fileNames: ["e1Gift.png"],
resizeOptions: {
width: 300,
height: 500,
},
}),
createWebPGenerator({
presetName: "webp-blur",
quality: 40,
fileNames: [
"random0.png",
"random1.png",
"random2.png",
"random3.png",
],
}),
],
}),
],
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"], // 확장자 목록에 .jsx 추가
},
plugins: [
new HtmlWebPackPlugin({
template: "./public/index.html", // public/index.html 파일을 읽는다.
filename: "index.html", // output으로 출력할 파일은 index.html 이다.
}),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
"process.env.RANDOM_URL": JSON.stringify(process.env.RANDOM_URL),
"process.env.FCFS_URL": JSON.stringify(process.env.FCFS_URL),
}),
new MiniCssExtractPlugin({
filename: "[name].bundle.css",
chunkFilename: "[id].css",
}),
],
};
};