-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
158 lines (141 loc) · 4.21 KB
/
vite.config.js
File metadata and controls
158 lines (141 loc) · 4.21 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
/**
* Unity AI Lab
* Creators: Hackall360, Sponge, GFourteen
* https://www.unityailab.com
* unityailabcontact@gmail.com
* Version: v2.1.5
*/
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import fs from 'fs';
export default defineConfig({
plugins: [
// Static copy plugin - apps directory now handled via rollupOptions and copy-assets.js
// viteStaticCopy({
// targets: []
// })
// Custom plugin to handle directory URLs -> index.html
{
name: 'rewrite-middleware',
configureServer(server) {
// Use pre middleware to run before Vite's default handling
return () => {
server.middlewares.use((req, res, next) => {
// Skip API routes and files with extensions
if (!req.url || req.url.startsWith('/api/') || req.url.includes('.')) {
return next();
}
// Normalize URL path
let urlPath = req.url.split('?')[0]; // Remove query string
if (!urlPath.endsWith('/')) {
urlPath += '/';
}
const filePath = resolve(__dirname, '.' + urlPath + 'index.html');
if (fs.existsSync(filePath)) {
// Redirect to URL with trailing slash if needed (keeps relative paths working)
if (!req.url.endsWith('/') && !req.url.includes('?')) {
res.writeHead(302, { Location: req.url + '/' });
res.end();
return;
}
req.url = urlPath + 'index.html';
}
next();
});
};
},
},
],
// Base public path
base: './',
// Build configuration
build: {
outDir: 'dist',
emptyOutDir: true,
// Multi-page app configuration
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
about: resolve(__dirname, 'about/index.html'),
contact: resolve(__dirname, 'contact/index.html'),
services: resolve(__dirname, 'services/index.html'),
projects: resolve(__dirname, 'projects/index.html'),
ai: resolve(__dirname, 'ai/index.html'),
demo: resolve(__dirname, 'ai/demo/index.html'),
apps: resolve(__dirname, 'apps/index.html'),
},
output: {
// Aggressive content-based cache busting
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
// Manual chunks for better caching strategy
manualChunks(id) {
// Vendor chunks
if (id.includes('node_modules')) {
return 'vendor';
}
// Demo-specific modules - keep separate from main site
if (id.includes('ai/demo/js/')) {
return 'demo';
}
// Main site shared modules (from /js/ directory)
if (id.includes('/js/') && !id.includes('ai/demo/js/')) {
return 'main-shared';
}
},
},
},
// Asset handling
assetsInlineLimit: 4096, // 4kb - inline smaller assets
cssCodeSplit: true,
// Minification
minify: 'terser',
terserOptions: {
compress: {
drop_console: false, // Keep console logs for now
drop_debugger: true,
passes: 2,
},
format: {
comments: false,
},
},
// Sourcemaps for debugging (can disable in production)
sourcemap: false,
// Generate manifest for tracking asset versions
manifest: false,
},
// Server configuration for development
server: {
port: 3000,
open: true,
cors: true,
proxy: {
// Proxy API requests to avoid CORS issues in development
'/api/visitors': {
target: 'https://users.unityailab.com',
changeOrigin: true,
secure: true,
},
},
// Handle multi-page app routing
fs: {
strict: false,
},
},
// Resolve configuration for proper page routing
resolve: {
alias: {
'@': resolve(__dirname, './'),
},
},
// App type for proper HTML handling
appType: 'mpa',
// Preview server (for testing production build)
preview: {
port: 4173,
open: true,
},
});