-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathvite.config.js
110 lines (108 loc) · 3.1 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
import { defineConfig, loadEnv } from 'vite';
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { TDesignResolver } from 'unplugin-vue-components/resolvers';
export default ({ mode }) => {
const { VITE_PORT, VITE_BASE_URL } = loadEnv(mode, process.cwd());
return defineConfig({
base: VITE_BASE_URL,
plugins: [
vue(),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
IconsResolver({
prefix: 'Icon',
}),
],
eslintrc: {
enabled: true,
},
dts: true,
}),
Components({
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
IconsResolver({
enabledCollections: ['lets-icons'],
}),
],
}),
Icons({
autoInstall: true,
}),
],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import (reference) "${resolve('src/style/variables.less')}";`,
},
math: 'strict',
javascriptEnabled: true,
},
},
},
optimizeDeps: {
include: ['mitt', 'dayjs', 'axios', 'pinia', '@vueuse/core'],
exclude: ['@iconify-icons/lets-icons'],
},
server: {
// 端口号
port: VITE_PORT,
// 监听所有地址
host: '0.0.0.0',
// 服务启动时是否自动打开浏览器
open: true,
// 允许跨域
cors: true,
// 自定义代理规则
proxy: {},
// 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
warmup: {
clientFiles: ['./index.html', './src/{views,components}/*'],
},
},
build: {
// 设置最终构建的浏览器兼容目标
target: 'es2015',
// 构建后是否生成 source map 文件
sourcemap: false,
// chunk 大小警告的限制(以 kbs 为单位)
chunkSizeWarningLimit: 2000,
// 启用/禁用 gzip 压缩大小报告
reportCompressedSize: false,
// 自定义底层的 Rollup 打包配置
rollupOptions: {
output: {
// 指定 chunks 的入口文件模式
entryFileNames: 'static/js/[name]-[hash].js',
// 对代码分割中产生的 chunk 自定义命名
chunkFileNames: 'static/js/[name]-[hash].js',
// 自定义构建结果中的静态资源名称
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
// 压缩 Rollup 产生的额外代码
compact: true,
// 创建自定义的公共 chunk
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
},
},
},
},
});
};