-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
77 lines (70 loc) · 1.97 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
import { join, resolve } from 'node:path'
import type { ProxyOptions } from 'vite'
import { defineConfig, loadEnv } from 'vite'
import Vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import { openapi2ts } from './plugins'
export default defineConfig(({ mode }) => {
const ENV = loadEnv(mode, '.') as ImportMetaEnv
// eslint-disable-next-line no-console
console.log('[ENV]', ENV)
if ([
ENV.VITE_API_AUTH_USERNAME,
ENV.VITE_API_AUTH_PASSWORD,
ENV.VITE_IMG_SERVER_USERNAME,
ENV.VITE_IMG_SERVER_PASSWORD,
].some(token => !token))
throw new Error('所需的前置开发信息缺失,请查看Apifox或联系管理员获取')
const proxy: Record<string, string | ProxyOptions> = {
[ENV.VITE_API_BASE]: {
target: ENV.VITE_API_PROXY_TARGET,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`${ENV.VITE_API_BASE}`), ''),
},
[ENV.VITE_ASSETS_BASE]: {
target: ENV.VITE_ASSETS_PROXY_TARGET,
changeOrigin: true,
rewrite: path => path.replace(new RegExp(`${ENV.VITE_ASSETS_BASE}`), ''),
},
}
return {
server: {
host: '0.0.0.0',
port: 9001,
cors: true,
proxy,
},
preview: {
host: '0.0.0.0',
port: 13101,
cors: true,
proxy,
},
resolve: {
alias: [
{
find: /^@\//,
replacement: `${resolve(__dirname, 'src')}/`,
},
],
},
plugins: [
Vue(),
VueJsx(),
AutoImport({
imports: ['vue', '@vueuse/core', 'vue-router'],
dts: './types/auto-imports.d.ts',
}),
openapi2ts([
{
schemaPath: `${ENV.VITE_API_PROXY_TARGET}/v3/api-docs`,
requestImportStatement: 'import { request } from \'@/utils\'',
serversPath: join('./src/api'),
apiPrefix: '',
projectName: 'api',
},
], ENV.VITE_DEVELOPMENT_MODE === 'offline'),
],
}
})