-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
134 lines (122 loc) · 4.38 KB
/
Copy pathvite.config.ts
File metadata and controls
134 lines (122 loc) · 4.38 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
import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import {copyFileSync, existsSync} from 'fs'
import * as path from 'node:path'
import {seoFilesPlugin} from "./vite-plugins/seoFilesPlugin";
// https://vite.dev/config/
export default defineConfig(({mode}) => {
return {
plugins: [
tailwindcss(),
react({
// Optimize JSX runtime
jsxRuntime: 'automatic'
}),
{
name: 'copy-support-files',
writeBundle() {
if(existsSync('public/github-proxy.php')) {
copyFileSync('public/github-proxy.php', 'dist/github-proxy.php');
}
if(existsSync('public/profile-data.json')) {
copyFileSync('public/profile-data.json', 'dist/profile-data.json');
}
if(existsSync('public/.htaccess')) {
copyFileSync('public/.htaccess', 'dist/.htaccess');
}
}
},
seoFilesPlugin()
],
resolve: {
alias: {
'@' : path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
'@hooks' : path.resolve(__dirname, './src/hooks'),
'@utils' : path.resolve(__dirname, './src/utils'),
'@types' : path.resolve(__dirname, './src/types'),
'@assets' : path.resolve(__dirname, './src/assets')
},
},
// Optimized build configuration
build: {
target: 'es2015',
minify: 'terser',
rollupOptions: {
output: {
// Optimize chunk splitting
manualChunks: {
// Vendor chunks
'react-vendor': [
'react',
'react-dom'
],
'router' : ['react-router-dom'],
},
// Optimize file names for caching
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const info = assetInfo.name?.split('.');
if(!info) {
return 'assets/[name]-[hash][extname]';
}
const ext = info[info.length - 1];
if(/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(ext)) {
return `assets/images/[name]-[hash][extname]`;
}
if(/woff|woff2|eot|ttf|otf/i.test(ext)) {
return `assets/fonts/[name]-[hash][extname]`;
}
return `assets/[name]-[hash][extname]`;
}
}
},
// Report bundle size
reportCompressedSize : true,
chunkSizeWarningLimit: 1000,
// Source maps for production debugging
sourcemap: mode !== 'production' ? 'inline' : false
},
// CSS optimization
css: {
modules : {
localsConvention: 'camelCase'
},
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/variables.scss";`
}
}
},
// Development server
server: {
port: 3000,
open: true,
cors: true
},
// Preview server
preview: {
port: 4173,
open: true
},
// Define environment variables
define: {
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
__BUILD_TIME__ : JSON.stringify(new Date().toISOString())
},
// Optimize dependencies
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router-dom'
],
exclude: [
'@vite/client',
'@vite/env'
]
}
}
})