-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
101 lines (94 loc) · 2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import AutoImport from "unplugin-auto-import/vite";
import qiankun from "vite-plugin-qiankun";
import dayjs from "dayjs";
import Unocss from "unocss/vite";
import pkg from "./package.json";
const { dependencies, devDependencies, name, version, description } = pkg
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version, description },
lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
const publicPathMap: { [key: string]: string } = {
production: "prod",
gray: "gray",
test: "test",
tice: "tice",
};
const getPublicPath = (mode: string) => {
const OssUrl =
mode === "production"
? "https://xxxxxxx.com/"
: "https://xxxxxxx.com/";
const base = `${OssUrl}/${name}/${publicPathMap[mode]}/`;
return base;
// 测试环境: vue3-antd4-admin,生产环境:/
return mode === "test" ? '/vue3-antd4-admin' : '/'
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
// 根据当前工作目录中的 `mode` 加载 .env 文件
// 设置第三个参数为 '' 来加载所有环境变量,而不管是否有 `VITE_` 前缀。
const env = loadEnv(mode, process.cwd(), '')
const root = process.cwd();
const config = {
root,
base: mode === "development" ? "/" : getPublicPath(mode),
envDir: fileURLToPath(new URL('./env', import.meta.url)),
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
__APP_ENV__: JSON.stringify(env.APP_ENV),
},
plugins: [
vue(),
vueJsx(),
Components({
dirs: ['src/components'],
extensions: ["vue"],
include: [/\.vue$/, /\.vue\?vue/],
resolvers: [AntDesignVueResolver({
importStyle: false, // css in js
})],
dts: "src/types/components.d.ts",
}),
AutoImport({
imports: ["vue", "vue-router"],
resolvers: [AntDesignVueResolver()],
dts: "src/types/auto-import.d.ts",
eslintrc: {
enabled: true
},
}),
// useDevMode 开启时与热更新插件冲突,使用变量切换
// 如果是在主应用中加载子应用vite,必须打开这个,否则 vite 加载不成功, 单独运行没影响
qiankun(name, {
useDevMode: true
}),
Unocss(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
host: "0.0.0.0",
port: 3000,
open: true,
cors: true,
proxy: {
"/api": {
target: "http://xxxxx:32584",
changeOrigin: true,
// rewrite: (path: string) => path.replace(/^\/api/, ""),
}
}
},
}
return config
})