-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
58 lines (53 loc) · 1.58 KB
/
Copy pathvite.config.ts
File metadata and controls
58 lines (53 loc) · 1.58 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
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, loadEnv, PluginOption } from "vite";
import sparkPlugin from "@github/spark/spark-vite-plugin";
import createIconImportProxy from "@github/spark/vitePhosphorIconProxyPlugin";
import { resolve } from 'path';
const projectRoot = process.env.PROJECT_ROOT || import.meta.dirname;
// HTML escape function to prevent XSS
function escapeHtml(unsafe: string): string {
return unsafe
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, projectRoot, '');
const appName = env.APP_CONFIG_APP_NAME?.trim() || 'Enterprise Support';
return {
plugins: [
react(),
tailwindcss(),
// DO NOT REMOVE
createIconImportProxy() as PluginOption,
sparkPlugin() as PluginOption,
{
name: 'html-transform',
transformIndexHtml(html) {
return html.replace(
/<title>.*?<\/title>/,
`<title>${escapeHtml(appName)}</title>`
);
},
} as PluginOption,
],
envPrefix: ['VITE_', 'APP_CONFIG_'],
// Use Lightning CSS transformer for better CSS optimization and error recovery
// errorRecovery allows the build to continue even if there are non-critical CSS parsing issues
css: {
transformer: 'lightningcss',
lightningcss: {
errorRecovery: true,
},
},
resolve: {
alias: {
'@': resolve(projectRoot, 'src')
}
},
};
});