-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
94 lines (87 loc) · 2.41 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
import { lingui } from '@lingui/vite-plugin'
import react from '@vitejs/plugin-react-swc'
import { resolve } from 'path'
import { PluginOption, ProxyOptions, defineConfig, loadEnv } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import mockDevServerPlugin from 'vite-plugin-mock-dev-server'
import svgr from 'vite-plugin-svgr'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '')
const plugins: PluginOption = [
react({
plugins: [['@lingui/swc-plugin', {}]],
}),
svgr(),
lingui(),
createHtmlPlugin({
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}),
]
if (env.VITE_USE_MOCK === 'true') {
plugins.push(
mockDevServerPlugin({
prefix: '/api',
wsPrefix: '^/api/workspaces/[a-z0-9\\-]+/events',
include: ['mock-apis/**/*.mock.ts'],
log: 'debug',
build: {
log: 'debug',
},
}),
)
}
const proxy: Record<string, string | ProxyOptions> =
env.VITE_USE_PROXY === 'true'
? {
'/api': {
target: env.VITE_SERVER,
changeOrigin: true,
},
[`^/api/workspaces/[a-z0-9\\-]+/events`]: {
target: env.VITE_WS_SERVER,
changeOrigin: true,
ws: true,
},
}
: undefined
const serverOptions = {
port: env.PORT ? Number(env.PORT) : undefined,
host: env.HOST ?? undefined,
proxy,
}
return {
base: process.env.PUBLIC_URL ?? '/',
plugins,
build: {
// manifest: '/public/manifest.json',
sourcemap: true,
rollupOptions: {
onwarn(warning, defaultHandler) {
if (warning.code === 'SOURCEMAP_ERROR') {
return
}
defaultHandler(warning)
},
},
},
server: serverOptions,
preview: serverOptions,
resolve: {
alias: [{ find: 'src', replacement: resolve(__dirname, 'src') }],
},
}
})