-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
54 lines (53 loc) · 1.6 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
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// 打包时间戳,防止打包部署后用户页面出现缓存问题
const timestamp = new Date().getTime()
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
// 暂时取消按需导入,因为按需导入会出现用户等待时间,不友好
// 按需自动导入elementPlus,不需要手动import否则样式会出错
// AutoImport({
// resolvers: [ElementPlusResolver()]
// }),
// Components({
// resolvers: [ElementPlusResolver()]
// })
],
base: '/', //路由前缀
resolve: {
// @的配置
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
// 反向代理
server: {
open: true, // 服务启动时是否自动打开浏览器
proxy: {
"/api": {
target: "http://localhost:9291",
changeOrigin: true,
// 前端api路由重新,比如api要重写成api2
// rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
build: {
rollupOptions: {
output: {
// 入口文件名
entryFileNames: `assets/[name].${timestamp}.js`,
// 块文件名
chunkFileNames: `assets/[name]-[hash].${timestamp}.js`,
// 资源文件名 css 图片等等
assetFileNames: `assets/[name]-[hash].${timestamp}.[ext]`,
},
},
}
})