-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.ts
99 lines (95 loc) Β· 2.96 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
import * as path from "path";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import webpack, { DefinePlugin } from "webpack";
import CopyWebpackPlugin from "copy-webpack-plugin";
import { sbtiResults } from "./src/constants/sbti";
const production = process.env.NODE_ENV === "production";
const development =
!process.env.NODE_ENV || process.env.NODE_ENV === "development";
const config: webpack.Configuration = {
mode: development ? "development" : "production",
entry: "./src/index.tsx",
output: {
filename: production ? "[name]-bundle-[chunkhash:8].js" : "[name].js",
path: path.resolve(__dirname, "dist"),
publicPath: process.env.PUBLIC_PATH ?? "/",
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".mjs"],
modules: [path.join(__dirname, "src"), "node_modules"],
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(mjs|js|jsx|ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
cacheDirectory: true,
babelrc: true,
},
},
},
{
test: /\.(png|ico|ttf|woff2?|eot|otf|svg)$/,
loader: "file-loader",
},
],
},
plugins: [
new DefinePlugin({
"process.env": {
BASE_NAME: JSON.stringify(process.env.BASE_NAME ?? "/"),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
},
}),
new CopyWebpackPlugin({ patterns: [{ from: "src/static" }] }),
new MiniCssExtractPlugin(),
new CleanWebpackPlugin(),
new ForkTsCheckerWebpackPlugin({
async: false,
eslint: {
files: "src/**/*.{ts,tsx,js,jsx}",
},
}),
new HtmlWebpackPlugin({
template: "src/index.html",
title: "λΏμμ΄ ν
μ€νΈ",
description: "λΏμμ΄λ‘ μμ보λ μ±ν₯ ν
μ€νΈ",
image: "https://ssungbti.yourssu.com/img/open.png?v=2",
url: "https://ssungbti.yourssu.com/",
}),
...sbtiResults.map(
sbti =>
new HtmlWebpackPlugin({
template: "src/index.html",
filename: `result/${sbti.type}/index.html`,
title: "λΏμμ΄ ν
μ€νΈ",
description: `${sbti.subtitle} ${sbti.title}`,
image: `https://ssungbti.yourssu.com/img/${sbti.type}.png`,
url: `https://ssungbti.yourssu.com/result/${sbti.type}/`,
})
),
],
devServer: {
hot: true,
historyApiFallback: true,
},
devtool: development ? "inline-source-map" : undefined,
};
if (development) {
config.plugins = config.plugins?.concat([
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
]);
}
export default config;