优化全局配置
This commit is contained in:
@@ -1,2 +1,5 @@
|
|||||||
# 开发环境
|
# 开发环境
|
||||||
VITE_APP_BASE_API = '/api'
|
VITE_APP_BASE_API='/api'
|
||||||
|
|
||||||
|
|
||||||
|
VITE_APP_BASE_URL='http://192.168.1.38:18081'
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
# 生产环境
|
# 生产环境
|
||||||
VITE_APP_BASE_API = '/prod-api'
|
VITE_APP_BASE_API=/prod-api
|
||||||
|
|
||||||
|
VITE_APP_BASE_URL=http://127.0.0.1:18081
|
||||||
1
global.d.ts
vendored
1
global.d.ts
vendored
@@ -2,4 +2,3 @@
|
|||||||
declare module '@/components/*';
|
declare module '@/components/*';
|
||||||
declare module '@/views/*';
|
declare module '@/views/*';
|
||||||
declare module '@/api/*';
|
declare module '@/api/*';
|
||||||
declare module '@/App.vue';
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const errCodeMap: { [key: string]: string } = {
|
|||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_APP_BASE_API as string,
|
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||||
timeout: 10000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ service.interceptors.request.use(
|
|||||||
// 响应拦截器
|
// 响应拦截器
|
||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
response => {
|
response => {
|
||||||
console.log(response)
|
// console.log(response);
|
||||||
const code = response.data.code || 200;
|
const code = response.data.code || 200;
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
import Components from "unplugin-vue-components/vite"; // 按需组件自动导入
|
import Components from "unplugin-vue-components/vite"; // 按需组件自动导入
|
||||||
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
|
import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
|
||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
@@ -7,44 +7,49 @@ import IconsResolver from 'unplugin-icons/resolver';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
resolve: {
|
|
||||||
alias: {
|
const env = loadEnv(mode, process.cwd());
|
||||||
"@": path.resolve(__dirname, "src"),
|
|
||||||
},
|
return {
|
||||||
},
|
resolve: {
|
||||||
server: {
|
alias: {
|
||||||
proxy: {
|
"@": path.resolve(__dirname, "src"),
|
||||||
"/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,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
server: {
|
||||||
plugins: [
|
proxy: {
|
||||||
vue(),
|
"/api": {
|
||||||
Components({
|
target: env.VITE_APP_BASE_URL,
|
||||||
dts: true, //生成components.d.ts 全局定义文件
|
changeOrigin: true,
|
||||||
resolvers: [
|
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||||
AntDesignVueResolver({
|
},
|
||||||
//对使用到的全局ant design vue组件进行类型导入
|
"/prod-api": {
|
||||||
importStyle: false, // 不动态引入css,这个不强求
|
target: env.VITE_APP_BASE_URL,
|
||||||
}),
|
changeOrigin: true,
|
||||||
// 自动导入 lucide 图标
|
},
|
||||||
IconsResolver({
|
},
|
||||||
prefix: "i", // 比如用 <i-a-arrow-down />
|
},
|
||||||
enabledCollections: ["lucide"],
|
plugins: [
|
||||||
}),
|
vue(),
|
||||||
],
|
Components({
|
||||||
include: [/\.vue$/, /\.vue\?vue/, /\.md$/, /\.tsx$/], //包含的文件类型
|
dts: true, //生成components.d.ts 全局定义文件
|
||||||
}),
|
resolvers: [
|
||||||
Icons({
|
AntDesignVueResolver({
|
||||||
autoInstall: true, // 没安装的图标库会自动下载
|
//对使用到的全局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, // 没安装的图标库会自动下载
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user