-
Notifications
You must be signed in to change notification settings - Fork 52
/
vite.config.ts
72 lines (70 loc) · 1.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
// vite.config.ts
import { defineConfig, loadEnv, Plugin } from 'vite';
import path from 'path';
import react from '@vitejs/plugin-react-swc';
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import SemiPlugin from './src/lib/semi';
import UnoCSS from 'unocss/vite';
import { execSync } from 'child_process';
// Plugin to get Git hash
function gitHashPlugin(): Plugin {
return {
name: 'git-hash-plugin',
config: () => {
const hash = execSync('git rev-parse HEAD').toString().trim();
return {
define: {
__GIT_HASH__: JSON.stringify(hash),
},
};
},
};
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
console.debug('print current base path', env.BASE_PATH);
return {
base: env.BASE_PATH || '/',
plugins: [
tsconfigPaths({ root: './' }),
react(),
UnoCSS(),
TanStackRouterVite(),
SemiPlugin({
theme: '@semi-bot/semi-theme-meilisearch',
}),
gitHashPlugin(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
host: true,
port: 24900,
},
css: {
modules: {
localsConvention: 'camelCaseOnly',
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
// node_modules is mostly the main reason for the large chunk problem,
// With this you're telling Vite to treat the used modules separately.
// To understand better what it does,
// try to compare the logs from the build command with and without this change.
if (id.includes('node_modules')) {
const importStrArr = id.toString().split('node_modules/');
return importStrArr[importStrArr.length - 1].split('/')[0].toString();
}
},
},
},
},
};
});