vue3-element-admin/vite.config.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

import { UserConfig, ConfigEnv, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import path from 'path';
// @see: https://gitee.com/holysheng/vite2-config-description/blob/master/vite.config.ts
export default ({ mode }: ConfigEnv): UserConfig => {
2022-05-08 13:06:12 +08:00
// 获取 .env 环境配置文件
const env = loadEnv(mode, process.cwd());
2022-05-08 13:06:12 +08:00
return {
plugins: [
vue(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]'
})
],
// 本地反向代理解决浏览器跨域限制
server: {
host: '0.0.0.0',
2022-05-08 13:06:12 +08:00
port: Number(env.VITE_APP_PORT),
open: true, // 运行自动打开浏览器
proxy: {
[env.VITE_APP_BASE_API]: {
// 线上API地址
2022-10-28 01:49:21 +08:00
target: 'http://vapi.youlai.tech',
// 本地API地址
// target: 'http://localhost:8989',
2022-05-08 13:06:12 +08:00
changeOrigin: true,
rewrite: path =>
path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
}
}
},
resolve: {
// Vite路径别名配置
alias: {
2022-05-15 20:31:53 +08:00
'@': path.resolve('./src')
2022-05-08 13:06:12 +08:00
}
}
};
};