-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
74 lines (64 loc) · 1.93 KB
/
vite.config.js
File metadata and controls
74 lines (64 loc) · 1.93 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 { defineConfig } from 'vite'
import { imagetools } from 'vite-imagetools'
export default defineConfig({
// Multi-page application support
appType: 'mpa',
// Proper base for GitHub Pages
// Use repository name if deploying to username.github.io/repo-name
// Use '/' if deploying to custom domain or username.github.io
base: '/', // Change this to '/' if using custom domain
// Image optimization plugin
plugins: [
imagetools({
// Default optimizations for different formats
defaultDirectives: (url) => {
// Apply WebP conversion and quality optimization to JPEG/PNG images
if (url.searchParams.has('optimize') ||
/\.(jpe?g|png)$/i.test(url.pathname)) {
return new URLSearchParams({
format: 'webp',
quality: '80'
})
}
return new URLSearchParams()
}
})
],
build: {
target: 'es2020', // Required for import.meta.url support
outDir: 'dist',
assetsDir: 'assets',
emptyOutDir: true,
// Enhanced asset organization for better caching
rollupOptions: {
output: {
// Organize assets by type with content hashing
assetFileNames: (assetInfo) => {
const extType = assetInfo.name.split('.').at(1)
if (/png|jpe?g|svg|gif|webp|avif/i.test(extType)) {
return `images/[name]-[hash][extname]`
}
if (/css/i.test(extType)) {
return `css/[name]-[hash][extname]`
}
if (/woff2?|eot|ttf|otf/i.test(extType)) {
return `fonts/[name]-[hash][extname]`
}
return `assets/[name]-[hash][extname]`
}
}
}
},
// Public directory for static assets
publicDir: 'public',
server: {
port: 3000,
open: true,
host: true, // Allow external connections (useful for network testing)
},
preview: {
port: 4173,
open: true,
host: true,
}
})