-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
74 lines (71 loc) · 2.32 KB
/
Copy pathvite.config.ts
File metadata and controls
74 lines (71 loc) · 2.32 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
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vitest/config';
import type { Plugin } from 'vite';
import react from '@vitejs/plugin-react';
/**
* The comparison panes render HTML that came out of a user-supplied .docx, so
* DOMPurify does the real work here — this policy is the second line of
* defense for the day a bypass lands. It ships as a meta tag rather than a
* response header because the deploy target is GitHub Pages, which serves
* static files and nothing else.
*
* `'unsafe-inline'` for styles is unavoidable: index.html carries an inline
* <style> block and React writes the theme through a style attribute.
* `frame-ancestors` and `report-uri` are left out because a meta-delivered
* policy ignores both.
*/
const CONTENT_SECURITY_POLICY = [
"default-src 'self'",
"script-src 'self'",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob:",
"font-src 'self'",
"connect-src 'self'",
"worker-src 'self' blob:",
"object-src 'none'",
"base-uri 'self'",
"form-action 'none'"
].join('; ');
function contentSecurityPolicy(): Plugin {
return {
name: 'doc-diff-pro:content-security-policy',
// Build only: in dev, @vitejs/plugin-react injects the react-refresh
// preamble as an inline module script that `script-src 'self'` would block.
apply: 'build',
transformIndexHtml: () => [
{
tag: 'meta',
attrs: { 'http-equiv': 'Content-Security-Policy', content: CONTENT_SECURITY_POLICY },
injectTo: 'head-prepend'
}
]
};
}
export default defineConfig({
base: process.env.VITE_BASE_PATH?.trim() || '/doc-diff-pro/',
plugins: [react(), contentSecurityPolicy()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
test: {
environment: 'jsdom',
globals: true,
include: ['src/**/*.test.{ts,tsx}'],
setupFiles: ['./src/test-utils/setup.ts'],
coverage: {
provider: 'v8',
include: ['src/**/*.{ts,tsx}'],
exclude: ['src/test-utils/**', 'src/types/**', 'src/main.tsx', 'src/vite-env.d.ts'],
// Floors sit just under the measured baseline: they guard against
// regression rather than mandating an increase.
thresholds: {
statements: 91,
branches: 83,
functions: 91,
lines: 94
}
}
}
});