-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
71 lines (64 loc) · 1.96 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
import react from "@vitejs/plugin-react-swc";
import path from "path";
import { defineConfig, loadEnv } from "vite";
import dts from "vite-plugin-dts";
import codegen from "vite-plugin-graphql-codegen";
import string from "vite-plugin-string";
import svgr from "vite-plugin-svgr";
import checkExistingCodegen from "./checkExistingCodegen";
const BUILD_DIR = "dist";
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd());
const isProductionMode = mode === "production";
const buildAliases = isProductionMode && {
"@/api/generated": path.resolve(__dirname, `${BUILD_DIR}/temp_api`),
};
const { codegenFileExists } = checkExistingCodegen(isProductionMode);
return {
build: {
sourcemap: command === "build" && !isProductionMode,
outDir: BUILD_DIR,
rollupOptions: {
output: {
manualChunks: {
mui: ["@mui/material", "@emotion/styled", "@emotion/react"],
api: ["@apollo/client", "apollo-link-token-refresh", "graphql"],
forms: ["formik", "yup"],
mapbox: ["mapbox-gl"], // mapbox-gl is a large package, there is an issue on github about this, developers of this package try to fix it
},
},
},
},
server: {
port: Number(env.VITE_PORT),
},
preview: {
port: Number(env.VITE_PREVIEW_PORT),
},
resolve: {
alias: {
...buildAliases, // should be placed exactly there
"@": path.resolve(__dirname, "src"),
"@tests": path.resolve(__dirname, "tests"),
},
},
plugins: [
react(),
string(),
svgr({ include: "**/*.svg" }),
codegen({
runOnStart: !codegenFileExists,
throwOnStart: true,
runOnBuild: isProductionMode,
configOverrideOnBuild: {
hooks: {
afterAllFileWrite: () => {
dts();
},
},
},
}),
],
};
});