forked from imzyb/MiSub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
88 lines (86 loc) · 2.38 KB
/
vite.config.js
File metadata and controls
88 lines (86 loc) · 2.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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
plugins: [
vue(),
tailwindcss(),
{
name: 'html-transform-rocket-loader',
transformIndexHtml(html) {
// 自动为所有 module script 添加 data-cfasync="false" 以防止 Cloudflare Rocket Loader 破坏加载
return html.replace(/<script type="module"/g, '<script type="module" data-cfasync="false"');
}
}
],
// 性能优化构建配置
build: {
// 启用CSS代码分割
cssCodeSplit: true,
// 优化依赖预构建
commonjsOptions: {
include: [/node_modules/]
},
rollupOptions: {
output: {
// 手动代码分割(保守策略,避免循环依赖导致空白页)
manualChunks: {
vue: ['vue'],
router: ['vue-router'],
pinia: ['pinia']
},
// 优化文件名
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split('.')
const ext = info[info.length - 1]
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)) {
return `assets/media/[name]-[hash][extname]`
}
if (/\.(png|jpe?g|gif|svg)(\?.*)?$/i.test(assetInfo.name)) {
return `assets/img/[name]-[hash][extname]`
}
if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetInfo.name)) {
return `assets/fonts/[name]-[hash][extname]`
}
return `assets/${ext}/[name]-[hash][extname]`
}
}
},
// 压缩配置
minify: 'terser',
// terserOptions removed for debugging
},
// 开发服务器配置
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1:8787',
changeOrigin: true,
},
'/sub/': {
target: 'http://127.0.0.1:8787',
changeOrigin: true,
},
'^/(?!@|api/|sub/|assets/|@vite/|src/|icons/|images/)[^/]+/[^/]+$': {
target: 'http://127.0.0.1:8787',
changeOrigin: true,
},
// Catch-all proxy removed to fix SPA fallback
}
},
// 依赖优化
optimizeDeps: {
include: [
'vue',
'pinia'
]
},
// 路径解析
resolve: {
alias: {
'@': '/src'
}
}
})