-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
98 lines (93 loc) · 2.63 KB
/
vite.config.ts
File metadata and controls
98 lines (93 loc) · 2.63 KB
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
import react from '@vitejs/plugin-react'
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'
import checker from 'vite-plugin-checker'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const certPath = resolve(__dirname, 'cert/pandatech.it+3.pem')
const keyPath = resolve(__dirname, 'cert/pandatech.it+3-key.pem')
const hasCerts = existsSync(certPath) && existsSync(keyPath)
/**
* Auto-discovery of path aliases.
* Every top-level subfolder of `src/` becomes importable as `from 'foo'`.
* Add a matching entry in `tsconfig.app.json` paths so TS resolves it too.
*/
function getAliases() {
const srcPath = resolve(__dirname, 'src')
const entries = readdirSync(srcPath, { withFileTypes: true })
return entries
.filter(dirent => dirent.isDirectory())
.reduce<Record<string, string>>((acc, dirent) => {
acc[dirent.name] = resolve(srcPath, dirent.name)
return acc
}, {})
}
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
checker({
typescript: true,
eslint: {
useFlatConfig: true,
lintCommand: 'eslint .',
},
overlay: {
initialIsOpen: false,
},
}),
],
resolve: {
alias: getAliases(),
},
server: hasCerts
? {
https: {
key: readFileSync(keyPath),
cert: readFileSync(certPath),
},
host: 'react.pandatech.it',
port: 5173,
strictPort: true,
}
: {
port: 5173,
strictPort: true,
},
build: {
target: 'es2022',
sourcemap: true,
cssCodeSplit: true,
// antd alone is ~600kB minified / ~200kB gzipped — bump above that.
chunkSizeWarningLimit: 800,
rollupOptions: {
output: {
// Explicit vendor splitting for long-term browser caching:
// when your code changes, vendor chunks stay cached.
manualChunks(id) {
if (!id.includes('node_modules')) return
if (
id.includes('/antd/') ||
id.includes('/@ant-design/') ||
id.includes('/rc-')
) {
return 'antd-vendor'
}
if (id.includes('/@reduxjs/') || id.includes('/react-redux/')) {
return 'redux-vendor'
}
if (
id.includes('/react-router') ||
id.includes('/react-dom/') ||
id.includes('/react/') ||
id.includes('/scheduler/')
) {
return 'react-vendor'
}
return 'vendor'
},
},
},
},
})