-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
94 lines (91 loc) · 2.51 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import legacy from '@vitejs/plugin-legacy'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import {
ElementPlusResolver,
VueUseComponentsResolver
} from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'
const pathResolve = (dir: string) => resolve(__dirname, dir)
// https://vitejs.dev/config/
export default defineConfig({
base: './',
server: {
port: 4000,
open: true,
cors: true,
// 设置代理,根据我们项目实际情况配置
proxy: {
'/api': {
target: 'https://api.github.com/', // 后台服务地址
changeOrigin: true, // 是否允许不同源
secure: true, // 支持https
rewrite: path => path.replace(/^\/api/, '')
}
}
},
resolve: {
alias: {
'@': pathResolve('./src'),
views: pathResolve('./src/views'),
components: pathResolve('./src/components'),
assets: pathResolve('./src/assets')
}
},
plugins: [
vue(),
legacy({
targets: ['defaults', 'not IE 11']
}),
Components({
dts: true, // enabled by default if `typescript` is installed
resolvers: [
IconsResolver(),
ElementPlusResolver(),
VueUseComponentsResolver()
]
}),
Icons({
compiler: 'vue3',
autoInstall: true
}),
AutoImport({
dts: './src/auto-imports.d.ts',
imports: ['vue', 'pinia', 'vue-router', '@vueuse/core'],
resolvers: [ElementPlusResolver()],
// Generate corresponding .eslintrc-auto-import.json file.
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true
}
})
],
build: {
reportCompressedSize: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 2000,
// 在生产环境移除console.log
terserOptions: {
compress: {
drop_console: false,
pure_funcs: ['console.log', 'console.info'],
drop_debugger: true
}
},
minify: 'terser',
assetsDir: 'static/assets',
// 静态资源打包到dist下的不同目录
rollupOptions: {
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
}
})