-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvite.config.ts
More file actions
186 lines (179 loc) · 5.92 KB
/
vite.config.ts
File metadata and controls
186 lines (179 loc) · 5.92 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import react from "@vitejs/plugin-react";
import { readFileSync } from "fs";
import path from "path";
import { defineConfig } from "vite";
import { visualizer } from "rollup-plugin-visualizer";
import { defineConfig as defineVitestConfig } from "vitest/config";
// Read version from package.json
interface PackageJson {
version: string;
name: string;
[key: string]: any;
}
const packageJson: PackageJson = JSON.parse(
readFileSync(path.resolve("./package.json"), "utf8")
);
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => ({
plugins: [
// Enable React features
react(),
// Bundle size visualization (only in production builds)
...(mode === 'production' ? [visualizer({
filename: "./build/stats.html",
open: false,
gzipSize: true,
brotliSize: true,
template: 'treemap',
projectRoot: process.cwd(),
})] : []),
],
publicDir: "public",
server: {
port: 5173,
open: true,
headers: {
"Access-Control-Allow-Origin": "*",
// Security Headers for development
"Content-Security-Policy": "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self'; font-src 'self' data: https://fonts.gstatic.com; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests;",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
"Referrer-Policy": "strict-origin-when-cross-origin",
},
},
// Make APP_VERSION available globally
define: {
APP_VERSION: JSON.stringify(packageJson.version),
},
resolve: {
tsconfigPaths: true,
},
base: "./",
build: {
outDir: "build",
sourcemap: true,
commonjsOptions: {
include: [/node_modules/],
},
// Set target for rollup
target: "es2025",
// Remove terser configuration for now - use oxc minification
minify: "oxc",
// Add chunk size reporting
reportCompressedSize: true,
rollupOptions: {
output: {
manualChunks: (id) => {
// Create separate chunks for better code splitting
if (id.includes("node_modules")) {
// React and React DOM in separate chunk
if (id.includes("react") || id.includes("react-dom") || id.includes("scheduler")) {
return "react-vendor";
}
// Chart.js in separate chunk for lazy loading
// @kurkle/color is a required Chart.js dependency for color handling
if (id.includes("chart.js") || id.includes("@kurkle/color")) {
return "chart";
}
// React Error Boundary in separate chunk
if (id.includes("react-error-boundary")) {
return "react-vendor";
}
// Other vendor dependencies
return "vendor";
}
// Group widgets by category for better chunking efficiency
// Assessment Center Widgets (group together)
if (id.includes("/widgets/assessmentcenter/") && !id.includes("SecurityLevelWidget")) {
return "widgets-assessment";
}
// Business Value Widgets (group together)
if (id.includes("/widgets/businessvalue/")) {
return "widgets-business";
}
// Impact Analysis Widgets (group together)
if (id.includes("/widgets/impactanalysis/")) {
return "widgets-impact";
}
// Implementation Guide Widgets (Chart.js widgets separate)
if (id.includes("/widgets/implementationguide/")) {
if (id.includes("SecurityVisualizationWidget")) {
return "widgets-visualization";
}
// Other implementation widgets together
return "widgets-implementation";
}
},
},
external: (id) => id.includes(".test.") || id.includes("__mocks__"),
},
},
// Use defineConfig for test configuration from vitest/config to properly type the test property
...defineVitestConfig({
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./src/tests/vitest-setup.ts", "./src/tests/setup-tests.ts"],
include: ["src/**/*.test.{ts,tsx}"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html", "lcov"],
reportsDirectory: "./build/coverage",
exclude: [
"node_modules/**/*",
"**/node_modules/**/*",
"node_module",
"**/@kurkle/color/**",
"**/chart.js/**",
"**/react/**",
"**/react-dom/**",
"**/scheduler/**",
"**/*jsx-runtime*",
"dist/",
"cypress/**",
"scripts/",
"docs/",
"**/*.d.ts",
"**/*.config.{js,ts}",
"**/.eslintrc.js",
"**/vite.config.ts",
"**/*.cy.{js,jsx,ts,tsx}",
"src/tests/",
"**/*.stories.{js,jsx,ts,tsx}",
"src/index.tsx",
".dependency-cruiser.cjs",
],
// ISMS Secure Development Policy requirements (v1.0 release)
thresholds: {
statements: 80,
branches: 75,
functions: 80,
lines: 80,
},
},
reporters: [
[
"verbose",
{
showSummary: true,
showSuccesses: true,
showSkipped: true,
showFailed: true,
renderSuccesses: true,
},
],
"html",
],
outputFile: {
html: "./build/test-results/index.html",
},
// Configure types to ensure testing library matchers are recognized
typecheck: {
include: ["**/*.{test,spec}.{ts,tsx}"],
tsconfig: "./tsconfig.json",
},
},
}),
}));