forked from easy-temps/vue3-vant-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
104 lines (89 loc) · 2.4 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
103
104
import path from 'path'
import { loadEnv } from 'vite'
import type { ConfigEnv, UserConfig } from 'vite'
import { visualizer } from 'rollup-plugin-visualizer'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { viteVConsole } from 'vite-plugin-vconsole'
import mock from './build/mock/createMockServer'
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
return {
base: env.VITE_APP_PUBLIC_PATH,
define: {
'process.env.VUE_APP_API_BASE_URL': JSON.stringify(env.VITE_APP_API_BASE_URL),
'process.env.VUE_APP_PUBLIC_PATH': JSON.stringify(env.VITE_APP_PUBLIC_PATH),
},
plugins: [
vue(),
vueJsx(),
visualizer(),
legacy({
targets: ['defaults', 'not IE 11'],
}),
Components({
dts: true,
resolvers: [VantResolver()],
types: [],
}),
AutoImport({
include: [
/\.[tj]sx?$/,
/\.vue$/,
/\.vue\?vue/,
],
imports: [
'vue',
'vue-router',
'vitest',
],
dts: true,
}),
viteVConsole({
entry: [path.resolve('src/main.ts')],
localEnabled: command === 'serve',
enabled: false,
config: {
maxLogNumber: 1000,
theme: 'light',
},
}),
mock({
watch: true,
mockUrlList: [/api/],
cwd: process.cwd(),
enable: env.VITE_HTTP_MOCK && env.VITE_MOCK && process.env.NODE_ENV !== 'production',
}),
],
build: {
cssCodeSplit: false,
chunkSizeWarningLimit: 2048,
},
resolve: {
alias: {
'~@': path.join(__dirname, './src'),
'@': path.join(__dirname, './src'),
'~': path.join(__dirname, './src/assets'),
},
},
server: {
host: true,
port: 3000,
proxy: env.VITE_HTTP_MOCK && env.VITE_MOCK && process.env.NODE_ENV !== 'production'
? undefined
: {
'/api': {
// backend url
target: '',
ws: false,
changeOrigin: true,
},
},
},
}
}