-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
73 lines (69 loc) · 2.05 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
/// <reference types="vitest" />
import { defineConfig, loadEnv } from "vite";
import react from "@vitejs/plugin-react";
import checker from "vite-plugin-checker";
import nodePolyfills from "vite-plugin-node-stdlib-browser";
import * as path from "path";
export default ({ mode }) => {
const env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const proxy = getProxy(env);
// https://vitejs.dev/config/
return defineConfig({
base: "", // Relative paths
plugins: [
nodePolyfills(),
react(),
checker({
overlay: false,
typescript: true,
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
dev: {
logLevel: ["warning"],
},
},
}),
],
test: {
environment: "jsdom",
include: ["**/*.spec.{ts,tsx}"],
setupFiles: "./src/tests/setup.js",
exclude: ["node_modules", "src/tests/playwright"],
globals: true,
},
server: {
port: parseInt(env.VITE_PORT),
proxy: proxy,
},
resolve: {
alias: {
$: path.resolve(__dirname, "./src"),
},
},
});
};
function getProxy(env: Record<string, string>) {
const dhis2UrlVar = "VITE_DHIS2_BASE_URL";
const dhis2AuthVar = "VITE_DHIS2_AUTH";
const targetUrl = env[dhis2UrlVar];
const auth = env[dhis2AuthVar];
const isBuild = env.NODE_ENV === "production";
if (isBuild) {
return {};
} else if (!targetUrl) {
console.error(`Set ${dhis2UrlVar}`);
process.exit(1);
} else if (!auth) {
console.error(`Set ${dhis2AuthVar}`);
process.exit(1);
} else {
return {
"/dhis2": {
target: targetUrl,
changeOrigin: true,
auth: auth,
rewrite: path => path.replace(/^\/dhis2/, ""),
},
};
}
}