-
Notifications
You must be signed in to change notification settings - Fork 48
/
vite.config.ts
97 lines (95 loc) · 3.45 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
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import viteCompression from 'vite-plugin-compression' // 解决构建压缩
import eslintPlugin from 'vite-plugin-eslint'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
export default defineConfig(env => {
const root = process.cwd()
const envConfig = loadEnv(env.mode, root)
console.log(envConfig)
return {
plugins: [
// basicSsl(),
vue(),
eslintPlugin({
cache: false, // 取消检查缓存
exclude: [ // 忽略的文件&目录
'**/node_modules/**',
'**/dist/**',
'**/rabbit/**',
'**/public/**'
]
}),
viteCompression({
// 生成压缩包gz
verbose: true, // 输出压缩成功
disable: true, // 是否禁用
// filter // 默认为 /\.(js|mjs|json|css|html)$/i
threshold: 1, // 体积大于阈值会被压缩,单位是b
algorithm: 'gzip', // 压缩算法
ext: '.gz'// 生成的压缩包后缀
}),
/* 按需引入 */
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
})
],
base: './',
build: {
outDir: 'custom-avatar',
chunkSizeWarningLimit: 1200,
minify: 'esbuild',
cssCodeSplit: true, // 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
reportCompressedSize: false, // 启用/禁用 gzip 压缩大小报告。压缩大型输出文件可能会很慢,因此禁用该功能可能会提高大型项目的构建性能。
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@img': path.resolve(__dirname, 'src/assets/img'),
'@c': path.resolve(__dirname, 'src/components'),
'@views': path.resolve(__dirname, 'src/views')
}
},
css: {
modules: {
scopeBehaviour: 'local',
generateScopedName: '[local]___[hash:base64:5]',
localsConvention: 'camelCase'
},
preprocessorOptions: {
scss: {},
less: {
javascriptEnabled: true
}
}
},
server: {
open: false,
host: '0.0.0.0',
port: 1111,
https: false,
proxy: {
'/api': {
target: envConfig.VITE_APP_BASE_API || 'https://www.xiaoli.vip',
changOrigin: true,
secure: false,
logLevel: 'error',
rewrite: (path) => path.replace(/^\/api/, '')
}
}
}
}
})