-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
87 lines (81 loc) · 2.62 KB
/
Copy pathvite.config.ts
File metadata and controls
87 lines (81 loc) · 2.62 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
/* spell-checker: ignore middlewares */
import { defineConfig } from 'vite';
import type { Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import fs from 'node:fs';
function lambdaProxyPlugin(): Plugin {
return {
name: 'lambda-local-proxy',
configureServer(server) {
const lambdaLocalProxy = require('@project/lambdas/build/script/lambdaLocalProxy');
lambdaLocalProxy(server.middlewares, 'serviceApi');
},
};
}
export default defineConfig({
plugins: [
react(),
lambdaProxyPlugin(),
],
resolve: {
preserveSymlinks: true,
// Replaces the vite-tsconfig-paths plugin; native in Vite 8 (experimental).
tsconfigPaths: true,
},
base: process.env.PUBLIC_URL || '/',
build: {
outDir: 'build',
sourcemap: true,
},
server: {
cors: { origin: true, credentials: true },
host: process.env.HOST || 'localhost',
port: parseInt(process.env.PORT || '3000', 10),
https: process.env.SSL_CRT_FILE ? {
cert: fs.readFileSync(process.env.SSL_CRT_FILE),
key: fs.readFileSync(process.env.SSL_KEY_FILE!),
} : undefined,
open: false,
proxy: {
'/accounts': {
target: 'https://dev.openstax.org',
changeOrigin: true,
autoRewrite: true,
cookieDomainRewrite: '',
configure: (proxy) => {
proxy.on('proxyReq', (proxyReq, req) => {
// vite's HTTPS dev server runs over HTTP/2, where the host header
// is delivered as the `:authority` pseudo-header instead of `host`.
const host = req.headers.host || req.headers[':authority'];
if (typeof host === 'string') {
proxyReq.setHeader('X-Forwarded-Host', host);
}
});
},
},
},
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setupTests.ts',
css: true,
server: {
deps: {
// These packages must be inlined so Vitest runs them through Vite's
// transform pipeline instead of Node's native ESM loader:
//
// @testing-library/jest-dom — its vitest entry uses CJS require('vitest')
// to call expect.extend(). Without inlining, Node resolves a separate
// CJS vitest instance from the ESM one the runner uses (the "dual
// package hazard"), so the extended expect has a different SnapshotClient
// than the one the runner initialized — breaking all snapshot matchers.
inline: [/@testing-library\/jest-dom/],
},
},
coverage: {
reporter: ['text-summary', 'html', 'lcovonly'],
include: ['src/*/**/*.{js,ts,tsx}'],
},
},
});