优化全局配置

This commit is contained in:
tao
2025-09-30 15:44:56 +08:00
parent db87adf26a
commit 27835e73ac
5 changed files with 54 additions and 45 deletions

View File

@@ -1,4 +1,4 @@
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';
import Components from "unplugin-vue-components/vite"; // 按需组件自动导入
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
import vue from '@vitejs/plugin-vue';
@@ -7,44 +7,49 @@ import IconsResolver from 'unplugin-icons/resolver';
import path from 'path';
// https://vite.dev/config/
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
server: {
proxy: {
"/api": {
target: "http://192.168.1.38:18081",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
"/prod-api": {
target: "http://127.0.0.1:18081",
changeOrigin: true,
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
return {
resolve: {
alias: {
"@": path.resolve(__dirname, "src"),
},
},
},
plugins: [
vue(),
Components({
dts: true, //生成components.d.ts 全局定义文件
resolvers: [
AntDesignVueResolver({
//对使用到的全局ant design vue组件进行类型导入
importStyle: false, // 不动态引入css,这个不强求
}),
// 自动导入 lucide 图标
IconsResolver({
prefix: "i", // 比如用 <i-a-arrow-down />
enabledCollections: ["lucide"],
}),
],
include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型
}),
Icons({
autoInstall: true, // 没安装的图标库会自动下载
}),
],
server: {
proxy: {
"/api": {
target: env.VITE_APP_BASE_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
"/prod-api": {
target: env.VITE_APP_BASE_URL,
changeOrigin: true,
},
},
},
plugins: [
vue(),
Components({
dts: true, //生成components.d.ts 全局定义文件
resolvers: [
AntDesignVueResolver({
//对使用到的全局ant design vue组件进行类型导入
importStyle: false, // 不动态引入css,这个不强求
}),
// 自动导入 lucide 图标
IconsResolver({
prefix: "i", // 比如用 <i-a-arrow-down />
enabledCollections: ["lucide"],
}),
],
include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型
}),
Icons({
autoInstall: true, // 没安装的图标库会自动下载
}),
],
}
});