-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathvite.config.ts
79 lines (77 loc) · 1.87 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
import { execSync } from "node:child_process";
import path from "node:path";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
import react from "@vitejs/plugin-react-swc";
import UnoCSS from "unocss/vite";
// vite.config.ts
import { type Plugin, defineConfig, loadEnv } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import SemiPlugin from "./src/lib/semi";
// 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,
},
preview: {
host: true,
port: 24900,
strictPort: true,
},
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();
}
},
},
},
},
};
});