Skip to content

Commit a970a58

Browse files
committed
Refactor Vite configuration for Plugin Vulnerability Scanner
- Simplified vite.config.js by removing unnecessary environment variable loading and path aliasing. - Set a fixed base URL for GitHub Pages deployment. - Streamlined build configuration by removing manual chunking and unnecessary options. - Updated server and preview headers for improved security. This refactor enhances clarity and maintainability of the Vite configuration.
1 parent fe1852e commit a970a58

File tree

1 file changed

+11
-121
lines changed

1 file changed

+11
-121
lines changed

vite.config.js

Lines changed: 11 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,16 @@
1-
import { defineConfig, loadEnv } from 'vite';
1+
import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
3-
import path from 'path';
43

5-
// https://vitejs.dev/config/
6-
export default defineConfig(({ command, mode }) => {
7-
// Load env vars for all modes
8-
const env = loadEnv(mode, process.cwd(), '');
9-
10-
const baseUrl = mode === 'production'
11-
? '/plugin-vulnerability-scanner/' // GitHub Pages base URL
12-
: '/';
13-
14-
return {
15-
plugins: [react()],
16-
17-
base: baseUrl, // Set the base URL for all assets
18-
19-
resolve: {
20-
alias: {
21-
'@': path.resolve(__dirname, './src')
22-
}
23-
},
24-
25-
// Development server configuration
26-
server: {
27-
// Proxy API requests during development
28-
proxy: {
29-
'/.netlify/functions/': {
30-
target: 'http://localhost:9999',
31-
changeOrigin: true,
32-
secure: false,
33-
rewrite: (path) => path.replace(/^\/.netlify\/functions/, '')
34-
}
35-
},
36-
37-
// Security headers
38-
headers: {
39-
'X-Frame-Options': 'DENY',
40-
'X-XSS-Protection': '1; mode=block',
41-
'X-Content-Type-Options': 'nosniff',
42-
'Referrer-Policy': 'strict-origin-when-cross-origin',
43-
'Content-Security-Policy': [
44-
"default-src 'self'",
45-
"connect-src 'self' http://localhost:9999 https://api.github.com",
46-
"script-src 'self' 'unsafe-inline'",
47-
"style-src 'self' 'unsafe-inline'",
48-
"img-src 'self' data: https:",
49-
"font-src 'self' data:",
50-
].join('; ')
51-
}
52-
},
53-
54-
// Build configuration
55-
build: {
56-
// Output directory for production build
57-
outDir: 'dist',
58-
assetsDir: 'assets', // Where to store assets in production
59-
60-
// Generate sourcemaps for production
61-
sourcemap: true,
62-
63-
// Minification options
64-
minify: 'terser',
65-
terserOptions: {
66-
compress: {
67-
drop_console: true, // Remove console.log in production
68-
drop_debugger: true
69-
}
70-
},
71-
72-
// Configure rollup
73-
rollupOptions: {
74-
output: {
75-
manualChunks: {
76-
// Split vendor code into chunks
77-
'vendor-react': ['react', 'react-dom'],
78-
'vendor-utils': ['lodash'],
79-
'vendor-ui': ['lucide-react', '@radix-ui/react-alert-dialog']
80-
},
81-
// Ensure assets use relative paths
82-
assetFileNames: (assetInfo) => {
83-
const info = assetInfo.name.split('.');
84-
const ext = info[info.length - 1];
85-
if (/\.(png|jpe?g|gif|svg|ico)$/.test(assetInfo.name)) {
86-
return `assets/images/[name]-[hash][extname]`;
87-
}
88-
if (/\.(css)$/.test(assetInfo.name)) {
89-
return `assets/css/[name]-[hash][extname]`;
90-
}
91-
if (/\.(woff|woff2|eot|ttf|otf)$/.test(assetInfo.name)) {
92-
return `assets/fonts/[name]-[hash][extname]`;
93-
}
94-
return `assets/[name]-[hash][extname]`;
95-
},
96-
chunkFileNames: 'assets/js/[name]-[hash].js',
97-
entryFileNames: 'assets/js/[name]-[hash].js',
98-
}
99-
}
100-
},
101-
102-
// Preview configuration (for testing production builds locally)
103-
preview: {
104-
headers: {
105-
'X-Frame-Options': 'DENY',
106-
'X-XSS-Protection': '1; mode=block',
107-
'X-Content-Type-Options': 'nosniff',
108-
'Referrer-Policy': 'strict-origin-when-cross-origin',
109-
'Content-Security-Policy': [
110-
"default-src 'self'",
111-
"connect-src 'self' https://api.github.com",
112-
"script-src 'self' 'unsafe-inline'",
113-
"style-src 'self' 'unsafe-inline'",
114-
"img-src 'self' data: https:",
115-
"font-src 'self' data:",
116-
].join('; ')
4+
export default defineConfig({
5+
plugins: [react()],
6+
base: '/plugin-vulnerability-scanner/', // Match GitHub Pages repository name
7+
build: {
8+
outDir: 'dist',
9+
assetsDir: 'assets',
10+
rollupOptions: {
11+
output: {
12+
manualChunks: undefined
11713
}
118-
},
119-
120-
// Environment variables to expose to the client
121-
define: {
122-
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
123-
__DEV__: mode === 'development'
12414
}
125-
};
15+
}
12616
});

0 commit comments

Comments
 (0)