forked from OpenBMB/XAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
92 lines (83 loc) · 2.76 KB
/
vite.config.ts
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
import react from '@vitejs/plugin-react'
import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv, UserConfigExport } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import banner from 'vite-plugin-banner'
import { resolve } from 'path'
import { createHtmlPlugin } from 'vite-plugin-html'
function pathResolve(dir: string) {
// const path = resolve(process.cwd(), '.', dir)
const path = resolve(__dirname, dir)
return path
}
const isProduction = process.env.type === 'prod'
process.env.VITE_MODE = isProduction ? 'production' : 'development'
export default defineConfig(({ command, mode }) => {
console.log('command', command, 'mode', mode)
console.log()
return {
base: './',
resolve: {
alias: [
{ find: /\/@\//, replacement: pathResolve('src') + '/' },
{ find: /\/#\//, replacement: pathResolve('types') + '/' },
{ find: /@\//, replacement: pathResolve('src') + '/' },
],
},
plugins: [
vue(),
react(),
banner(`build package in ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()} !`),
AutoImport({
resolvers: [ElementPlusResolver()],
imports: ['vue', '@vueuse/core', 'vue-router', 'pinia'],
dirs: ['./src/components/**/*', './src/composables/**', './src/store/**', './types/**'],
vueTemplate: true,
}),
Components({
dts: true,
resolvers: [ElementPlusResolver({ importStyle: true }), IconsResolver({ prefix: 'icon' })],
}),
Icons(),
createHtmlPlugin({
inject: { data: { title: 'X-Agent' } },
}),
],
// Define global constants replacement method. Each item will be defined globally in the development environment and statically replaced during building.
define: {
BASE_URL: JSON.stringify('/'),
},
server: {
proxy: {
'/api': {
target: loadEnv(mode, process.cwd()).VITE_BACKEND_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/\/api/, ''),
},
'/workspace': {
target: loadEnv(mode, process.cwd()).VITE_BACKEND_URL,
changeOrigin: true
},
},
},
build: {
cssTarget: 'chrome80',
minify: 'terser',
terserOptions: {
compress: {
keep_infinity: true,
drop_console: process.env.type === 'prod',
drop_debugger: true,
},
},
chunkSizeWarningLimit: 2000,
},
esbuild: {
drop: process.env.type === 'prod' ? ['console', 'debugger'] : [],
},
}
}) as UserConfigExport