-
Notifications
You must be signed in to change notification settings - Fork 495
/
Copy pathvite.config.js
76 lines (73 loc) · 2.35 KB
/
vite.config.js
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
/**********************************
* @Author: Ronnie Zhang
* @LastEditor: Ronnie Zhang
* @LastEditTime: 2023/12/05 21:31:02
* @Email: zclzone@outlook.com
* Copyright © 2023 Ronnie Zhang(大脸怪) | https://isme.top
**********************************/
import path from 'node:path'
import Vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import Unocss from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import { defineConfig, loadEnv } from 'vite'
import removeNoMatch from 'vite-plugin-router-warn'
import VueDevTools from 'vite-plugin-vue-devtools'
import { pluginIcons, pluginPagePathes } from './build/plugin-isme'
export default defineConfig(({ mode }) => {
const viteEnv = loadEnv(mode, process.cwd())
const { VITE_PUBLIC_PATH, VITE_PROXY_TARGET } = viteEnv
return {
base: VITE_PUBLIC_PATH || '/',
plugins: [
Vue(),
VueJsx(),
VueDevTools(),
Unocss(),
AutoImport({
imports: ['vue', 'vue-router'],
dts: false,
}),
Components({
resolvers: [NaiveUiResolver()],
dts: false,
}),
// 自定义插件,用于生成页面文件的path,并添加到虚拟模块
pluginPagePathes(),
// 自定义插件,用于生成自定义icon,并添加到虚拟模块
pluginIcons(),
// 移除非必要的vue-router动态路由警告: No match found for location with path
removeNoMatch(),
],
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
'~': path.resolve(process.cwd()),
},
},
server: {
host: '0.0.0.0',
port: 3200,
open: false,
proxy: {
'/api': {
target: VITE_PROXY_TARGET,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
secure: false,
configure: (proxy, options) => {
// 配置此项可在响应头中看到请求的真实地址
proxy.on('proxyRes', (proxyRes, req) => {
proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
})
},
},
},
},
build: {
chunkSizeWarningLimit: 1024, // chunk 大小警告的限制(单位kb)
},
}
})