-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
96 lines (93 loc) · 2.55 KB
/
vite.config.ts
File metadata and controls
96 lines (93 loc) · 2.55 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const isProduction = mode === 'production';
const isFrontendOnly = process.env.VITE_BUILD_TARGET === 'frontend' || process.env.GITHUB_ACTIONS;
// Determine base path - use repository name for GitHub Pages
const baseUrl = isFrontendOnly ? '/prism/' : '/';
return {
plugins: [
vue({
template: {
compilerOptions: {
// 处理自定义元素标签
isCustomElement: (tag) => tag.includes('-')
}
}
})
],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
server: {
port: 3000,
open: true,
fs: {
strict: false
},
// Add proxy for development to handle API calls
proxy: isFrontendOnly ? {} : {
'/api': {
target: 'http://localhost:3001',
changeOrigin: true,
secure: false
}
}
},
publicDir: 'public',
base: baseUrl,
build: {
outDir: 'dist',
assetsDir: 'assets',
sourcemap: false,
copyPublicDir: true,
emptyOutDir: true,
rollupOptions: {
external: isFrontendOnly ? [
'express',
'multer',
'ssh2-sftp-client',
'cors',
'dotenv',
'fs',
'path',
'events'
] : [],
output: {
manualChunks: undefined,
// Ensure proper asset naming for GitHub Pages
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: (assetInfo) => {
const info = assetInfo.name!.split('.')
const extType = info[info.length - 1]
if (/css/.test(extType)) {
return `assets/css/[name]-[hash].[ext]`
}
if (/png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)) {
return `assets/images/[name]-[hash].[ext]`
}
return `assets/[name]-[hash].[ext]`
}
}
},
chunkSizeWarningLimit: 1000,
minify: isProduction ? 'terser' : false,
terserOptions: isProduction ? {
compress: {
drop_console: true,
drop_debugger: true
}
} : undefined
},
// Add define to pass environment variables to the app
define: {
__IS_GITHUB_PAGES__: JSON.stringify(isFrontendOnly),
__BASE_URL__: JSON.stringify(baseUrl)
}
}
})