-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
122 lines (120 loc) · 3.29 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import viteCompression from 'vite-plugin-compression'
import viteImagemin from 'vite-plugin-imagemin'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
vueJsx(),
VueDevTools(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/ // .md
],
resolvers: [
ElementPlusResolver(),
IconsResolver({
prefix: 'Icon'
})
]
// imports: ['vue', 'vue-router', 'pinia']
}),
Components({
// dirs: ['src/components/**', 'src/components/**/**/*'],
resolvers: [
ElementPlusResolver(),
IconsResolver({
enabledCollections: ['ep']
})
]
}),
Icons({
autoInstall: true
}),
ElementPlus({
// options
}),
viteImagemin({
gifsicle: {
optimizationLevel: 7,
interlaced: false
},
optipng: {
optimizationLevel: 7
},
mozjpeg: {
quality: 20
},
pngquant: {
quality: [0.8, 0.9],
speed: 4
},
svgo: {
plugins: [
{
name: 'removeViewBox'
},
{
name: 'removeEmptyAttrs',
active: false
}
]
}
}),
viteCompression({
verbose: true, // 是否在控制台输出压缩结果
disable: false, // 是否禁用,相当于开关在这里
threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b,1b=8B, 1B=1024KB 这里相当于 9kb多,就会压缩
algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
ext: '.gz' //文件后缀名
})
],
css: {
// css预处理器
preprocessorOptions: {
css: {
// charset: false,
additionalData: `
@import "./src/assets/css/theme.scss";
@import "./src/assets/css/bem.scss";
`
}
}
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
base: './',
build: {
outDir: 'dist',
// assetsDir: "propertyData", // 指定生成静态资源的存放路径
target: 'esnext',
chunkSizeWarningLimit: 2000,
cssCodeSplit: true, //css 拆分
sourcemap: false, //不生成sourcemap
minify: 'terser', //是否禁用最小化混淆,esbuild打包速度最快,terser打包体积最小。
assetsInlineLimit: 5000, //小于该值 图片将打包成Base64
terserOptions: {
compress: {
drop_console: true, // 生产环境去掉控制台 console
drop_debugger: true, // 生产环境去掉控制台 debugger 默认就是true
dead_code: true // 删除无法访问的代码 默认就是true
}
}
}
})