-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
82 lines (77 loc) · 2.15 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
import { loadEnv } from "vite";
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react-swc";
import eslint from "vite-plugin-eslint";
import path from "path";
import fs from "fs";
// https://vitejs.dev/config/
export default ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const apiPath = process.env.VITE_API_HOST;
const inlineNewRelicPlugin = () => {
// We need to inline the relic_script in the index.html, you can dynamic include based on env here
// https://docs.newrelic.com/docs/browser/new-relic-browser/page-load-timing-resources/instrumentation-browser-monitoring/#javascript-placement
return {
name: "inline-javascript",
transformIndexHtml(html) {
const inlineJs = fs.readFileSync(
path.resolve(__dirname, "public/relic_script.js"),
"utf8"
);
return html.replace(
"<!-- new-relic-js -->",
`<script type='text/javascript'>${inlineJs}</script>`
);
},
};
};
return defineConfig({
server: {
watch: {
usePolling: true,
},
proxy: {
"/api/v1/ogc/collections": {
target: apiPath,
changeOrigin: true,
},
"/api/v1/ogc/tiles": {
target: apiPath,
changeOrigin: true,
},
"/api/v1/ogc/ext/autocomplete": {
target: apiPath,
changeOrigin: true,
},
"/api/v1/ogc/ext/parameter/vocabs": {
target: apiPath,
changeOrigin: true,
},
},
},
plugins: [
react(),
mode !== "test" &&
eslint({ exclude: ["/virtual:/**", "node_modules/**"] }),
inlineNewRelicPlugin(),
],
build: {
outDir: "dist",
},
test: {
globals: true,
// 👋 add the line below to add jsdom to vite
environment: "jsdom",
setupFiles: "./src/setupTests.ts",
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
},
},
publicDir: "public",
resolve: {
alias: [{ find: "@", replacement: path.resolve(__dirname, "src") }],
},
base: "",
});
};