forked from janhesters/react-router-saas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
88 lines (83 loc) · 2.16 KB
/
Copy pathvite.config.ts
File metadata and controls
88 lines (83 loc) · 2.16 KB
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
import { reactRouter } from "@react-router/dev/vite";
import tailwindcss from "@tailwindcss/vite";
import type { Plugin } from "vite";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig as defineVitestConfig } from "vitest/config";
// Custom plugin to handle .sudo files
const sudoFilesPlugin = {
name: "sudo-files",
transform(code: string, id: string) {
if (id.endsWith(".sudo")) {
return {
code: `export default ${JSON.stringify(code)}`,
map: undefined,
};
}
},
};
/**
* Vite plugin to add cache headers for static assets during development
*/
function staticCacheHeaders(): Plugin {
return {
configureServer(server) {
server.middlewares.use((request, response, next) => {
// Cache font files for 1 year in development
if (request.url?.startsWith("/fonts/")) {
response.setHeader(
"Cache-Control",
"public, max-age=31536000, immutable",
);
}
next();
});
},
name: "static-cache-headers",
};
}
const rootConfig = defineConfig({
plugins: [
tailwindcss(),
!process.env.VITEST && reactRouter(),
tsconfigPaths(),
staticCacheHeaders(),
sudoFilesPlugin,
],
server: { port: 3000 },
});
const testConfig = defineVitestConfig({
test: {
projects: [
{
...rootConfig,
test: {
env: { TZ: "UTC" },
include: ["app/**/*.test.ts"],
name: "unit-tests",
},
},
{
...rootConfig,
test: {
env: { TZ: "UTC" },
globalSetup: "app/test/vitest.global-setup.ts",
include: ["app/**/*.spec.ts"],
name: "integration-tests",
setupFiles: ["app/test/setup-server-test-environment.ts"],
},
},
{
...rootConfig,
test: {
env: { TZ: "UTC" },
environment: "happy-dom",
include: ["app/**/*.test.tsx"],
name: "react-happy-dom-tests",
setupFiles: ["app/test/setup-browser-test-environment.ts"],
},
},
],
},
});
export default defineConfig({ ...rootConfig, ...testConfig });