-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
102 lines (100 loc) · 3.24 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
import type { ConfigEnv, UserConfig } from 'vite'
import { loadEnv } from 'vite'
import { resolve } from 'path'
import legacy from '@vitejs/plugin-legacy'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vue from '@vitejs/plugin-vue'
import eslint from 'vite-plugin-eslint'
import stylelint from 'vite-plugin-stylelint'
import checker from 'vite-plugin-checker'
import { viteMockServe } from 'vite-plugin-mock'
import ElementPlus from 'unplugin-element-plus/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
export default ({ mode, command }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
// const isDev = mode === 'development'
return {
base: env.VITE_APP_PUBLIC_PATH,
plugins: [
vue(),
vueJsx(),
eslint({ cache: false }),
stylelint(),
legacy({
targets: ['defaults', 'not IE 11'],
}),
checker({
typescript: true,
vueTsc: true,
}),
// element-plus 组件自动导入
AutoImport({
resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
}),
Components({
resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
}),
ElementPlus({
useSource: true,
}),
viteMockServe({
mockPath: 'mock', // mock 数据的目录,相对于工作目录
localEnabled: command === 'serve' && env.VITE_MOCK === 'true',
supportTs: true,
watchFiles: true,
}),
],
resolve: {
alias: {
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
'@': resolve(__dirname, 'src'),
'@http': resolve(__dirname, 'src/services/http'),
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
additionalData: `
@use "@/styles/global/index.scss" as global;
`,
},
},
},
server: {
open: true, // 运行完后直接打开
host: true,
proxy: {
'/api': {
target: 'http//:1.1.1.1',
ws: false,
changeOrigin: true,
},
},
},
optimizeDeps: {
include: [
'element-plus/es/locale/lang/en',
'element-plus/es/locale/lang/zh-cn',
'dayjs/locale/eu',
'dayjs/locale/zh-cn',
],
},
build: {
cssCodeSplit: false,
chunkSizeWarningLimit: 2048,
rollupOptions: {
output: {
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
elementPlus: ['element-plus'],
dayjs: ['dayjs'],
},
},
},
},
}
}