-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
104 lines (102 loc) · 3.16 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
92
93
94
95
96
97
98
99
100
101
102
103
104
/// <reference types="vitest" />
import { type ConfigEnv, type UserConfigExport, loadEnv } from 'vite'
import path, { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import svgLoader from 'vite-svg-loader'
import UnoCSS from 'unocss/vite'
import viteLegacyPlugin from "@vitejs/plugin-legacy";
/** 配置项文档:https://cn.vitejs.dev/config */
export default (configEnv: ConfigEnv): UserConfigExport => {
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as ImportMetaEnv
const { VITE_PUBLIC_PATH } = viteEnv
return {
/** 打包时根据实际情况修改 base */
base: VITE_PUBLIC_PATH,
resolve: {
alias: {
/** @ 符号指向 src 目录 */
'@': resolve(__dirname, './src')
}
},
server: {
/** 是否开启 HTTPS */
https: false,
/** 设置 host: true 才可以使用 Network 的形式,以 IP 访问项目 */
host: true, // host: "0.0.0.0"
/** 端口号 */
port: 3333,
/** 是否自动打开浏览器 */
open: false,
/** 跨域设置允许 */
cors: true,
/** 端口被占用时,是否直接退出 */
strictPort: false,
/** 接口代理 */
proxy: {
'/lcd': {
target: 'https://www.fastmock.site/mock/761e2dda2b8890ab86c928a74e8f6538',
ws: true,
/** 是否允许跨域 */
changeOrigin: true
}
}
},
build: {
/** 单个 chunk 文件的大小超过 2048KB 时发出警告 */
chunkSizeWarningLimit: 2048,
/** 禁用 gzip 压缩大小报告 */
reportCompressedSize: false,
/** 打包后静态资源目录 */
assetsDir: 'static',
rollupOptions: {
output: {
/**
* 分块策略
* 1. 注意这些包名必须存在,否则打包会报错
* 2. 如果你不想自定义 chunk 分割策略,可以直接移除这段配置
*/
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
element: ['element-plus', '@element-plus/icons-vue'],
vxe: ['vxe-table', 'vxe-table-plugin-element', 'xe-utils']
}
}
}
},
/** 混淆器 */
esbuild: {
/** 打包时移除 console.log */
pure: ['console.log'],
/** 打包时移除 debugger */
drop: ['debugger'],
/** 打包时移除所有注释 */
legalComments: 'none'
},
/** Vite 插件 */
plugins: [
vue(),
vueJsx(),
/** 将 SVG 静态图转化为 Vue 组件 */
svgLoader({ defaultImport: 'url' }),
/** SVG */
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
symbolId: 'icon-[dir]-[name]'
}),
/** UnoCSS */
UnoCSS(),
/** 兼容性处理 */
viteLegacyPlugin({
targets: ['chrome 52'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
})
],
/** Vitest 单元测试配置:https://cn.vitest.dev/config */
test: {
include: ['tests/**/*.test.ts'],
environment: 'jsdom'
}
}
}