-
Notifications
You must be signed in to change notification settings - Fork 5
/
vite.config.ts
99 lines (95 loc) · 3.08 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
95
96
97
98
99
/// <reference types="vitest" />
/// <reference types="vite/client" />
import { defineConfig, loadEnv } from "vite";
import { resolve } from "path";
import autoprefixer from "autoprefixer";
import react from "@vitejs/plugin-react";
import eslint from "vite-plugin-eslint";
import svgrPlugin from "vite-plugin-svgr";
const projectRootDir = resolve(__dirname);
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
base: "/BMRG_APP_ROOT_CONTEXT/",
build: {
outDir: "build",
},
css: {
devSourcemap: mode !== "test",
preprocessorOptions: {
scss: {
quietDeps: true,
},
},
postcss: {
plugins: [autoprefixer],
},
},
plugins: [
react(),
eslint(),
svgrPlugin({
svgrOptions: {
icon: true,
},
}),
],
resolve: {
alias: [
{ find: "ApiServer", replacement: resolve(projectRootDir, "./src/ApiServer") },
{ find: "Assets", replacement: resolve(projectRootDir, "./src/Assets") },
{ find: "Components", replacement: resolve(projectRootDir, "./src/Components") },
{ find: "Config", replacement: resolve(projectRootDir, "./src/Config") },
{ find: "Constants", replacement: resolve(projectRootDir, "./src/Constants") },
{ find: "Features", replacement: resolve(projectRootDir, "./src/Features") },
{ find: "Hooks", replacement: resolve(projectRootDir, "./src/Hooks") },
{ find: "State", replacement: resolve(projectRootDir, "./src/State") },
{ find: "Styles", replacement: resolve(projectRootDir, "./src/Styles") },
{ find: "Types", replacement: resolve(projectRootDir, "./src/Types") },
{ find: "Utils", replacement: resolve(projectRootDir, "./src/Utils") },
{ find: "~ibm-design-colors", replacement: "ibm-design-colors" },
{ find: "~normalize-scss", replacement: "normalize-scss" },
],
},
server: {
port: 3000,
proxy: mode === "portforward" ? createPortforwardConfig(env.AUTH_JWT) : undefined,
},
test: {
css: false,
globals: true,
environment: "jsdom",
setupFiles: "./src/setupTests.tsx",
coverage: {
reporter: ["json"],
include: [
"**/src/Components/**/*.{js,jsx}",
"**/src/Features/**/*.{js,jsx}",
"**/src/Hooks/**/*.{js,jsx}",
"**/src/State/**/*.{js,jsx}",
"**/src/Utils/**/*.{js,jsx}",
],
},
},
};
});
const portForwardMap = {
"/api/launchpad": 8080,
"/api/catalog": 8080,
"/api/admin": 8082,
"/api/notifications": 8083,
"/api/users": 8084,
"/api/support": 8085,
};
// Map service context paths to the local port that you have forwarded
function createPortforwardConfig(jwt) {
return Object.entries(portForwardMap).reduce((proxyMap, [path, port]) => {
proxyMap[path] = {
changeOrigin: true,
headers: { Authorization: `Bearer ${jwt}` },
rewrite: (path) => path.replace(/^\/api/, ""),
target: `http://localhost:${port}`,
};
return proxyMap;
}, {});
}