-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
117 lines (97 loc) · 2.95 KB
/
vite.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
114
115
116
import path from 'path';
import {defineConfig, UserConfigExport, type PluginOption, loadEnv} from 'vite';
import react from '@vitejs/plugin-react';
import {visualizer} from 'rollup-plugin-visualizer';
import compression from 'vite-plugin-compression2';
const resolve = (dir) => path.join(__dirname, '.', dir);
// region [Common Config]
const commonConfig = () => ({
plugins: [
react(),
compression({
include: [/\.(js)$/, /\.(scss)$/],
threshold: 1400,
}),
],
resolve: {
extensions: ['.tsx', '.ts', '.scss', '.js'],
alias: {
// IntelliJ doesn't recognize vite alias yet
// Aliases should be set in tsconfig.json, main.ts as well
// @See https://youtrack.jetbrains.com/issue/WEB-55332/Vite-aliases-in-vite.config-support
'@': resolve('src'),
'~': resolve('src/components'),
'~style': resolve('src/styles'),
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "/src/styles/designToken/Entry.scss";',
},
},
devSourcemap: true,
},
envDir: './dotenv',
// @formatter:off
envPrefix: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
// @formatter:on
});
// endregion
// region [DevServer Config]
const devServerConfig = () => ({
server: {
port: 9090,
proxy: {
'/api/1.0': {
target: 'https://tks-api-dev.taco-cat.xyz',
changeOrigin: true,
headers: {
Connection: 'keep-alive',
},
},
},
},
preview: {
port: 7070,
},
});
// endregion
// region [Production Config]
const outputConfig = () => ({
build: {
outDir: 'dist',
},
});
// endregion
/**
* Vite Manual, Vite 매뉴얼
* https://vitejs.dev/config/
* https://vitejs-kr.github.io/
*/
export default defineConfig(
({mode, command}) => {
// dev (dev, serve), preview (prod, serve), build (prod, build)
let config: UserConfigExport = {...commonConfig()};
if (command === 'serve') {
config = {...config, ...devServerConfig()};
}
if (mode === 'production') {
config = {...config, ...outputConfig()};
if (process.env.npm_lifecycle_event === 'analyze') {
config.plugins = [
...config.plugins,
visualizer({
// https://github.com/btd/rollup-plugin-visualizer
title: 'TKS Bundle Report',
filename: './dist/tks-bundle-report.html',
open: true,
gzipSize: true,
}) as unknown as PluginOption,
];
}
}
return config;
},
);