mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2024-11-01 14:10:27 +08:00
添加代理 __PROXY_LIST__
This commit is contained in:
parent
98b7a9228f
commit
ab623bf1f0
@ -1,5 +1,7 @@
|
||||
import { isObject } from "../utils";
|
||||
|
||||
console.log(__PROXY_LIST__);
|
||||
|
||||
export function Permission(value: string) {
|
||||
return function (target: any, key: any, descriptor: any) {
|
||||
if (!target.permission) {
|
||||
@ -26,13 +28,18 @@ export function Service(value: any) {
|
||||
// 复杂项
|
||||
if (isObject(value)) {
|
||||
const { proxy, namespace, url, mock } = value;
|
||||
const item = __PROXY_LIST__[proxy];
|
||||
|
||||
if (proxy && !item) {
|
||||
console.error(`${proxy} 指向的地址不存在!`);
|
||||
}
|
||||
|
||||
target.prototype.namespace = namespace;
|
||||
target.prototype.mock = mock;
|
||||
|
||||
if (proxy) {
|
||||
target.prototype.proxy = proxy;
|
||||
target.prototype.url = url;
|
||||
target.prototype.url = url || item ? item.target : null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
2
src/shims-vue.d.ts
vendored
2
src/shims-vue.d.ts
vendored
@ -62,3 +62,5 @@ declare module "mockjs" {
|
||||
const Mock: any;
|
||||
export default Mock;
|
||||
}
|
||||
|
||||
declare const __PROXY_LIST__: any[];
|
||||
|
@ -1,5 +1,5 @@
|
||||
import path from "path";
|
||||
import type { UserConfig } from "vite";
|
||||
import { UserConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import vueJsx from "@vitejs/plugin-vue-jsx";
|
||||
import viteCompression from "vite-plugin-compression";
|
||||
@ -13,6 +13,21 @@ function resolve(dir: string) {
|
||||
// https://vitejs.dev/config/
|
||||
|
||||
export default (): UserConfig => {
|
||||
// 请求代理地址
|
||||
const proxy = {
|
||||
"/dev": {
|
||||
target: "http://127.0.0.1:8001",
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/dev/, "")
|
||||
},
|
||||
|
||||
"/pro": {
|
||||
target: "https://show.cool-admin.com",
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(/^\/pro/, "/api")
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
base: "/",
|
||||
plugins: [vue(), viteCompression(), Components(), vueJsx(), svgBuilder("./src/icons/svg/")],
|
||||
@ -32,23 +47,14 @@ export default (): UserConfig => {
|
||||
},
|
||||
server: {
|
||||
port: 9000,
|
||||
proxy,
|
||||
hmr: {
|
||||
overlay: true
|
||||
},
|
||||
proxy: {
|
||||
"/dev": {
|
||||
target: "http://127.0.0.1:8001",
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/dev/, "")
|
||||
},
|
||||
|
||||
"/pro": {
|
||||
target: "https://show.cool-admin.com",
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/pro/, "/api")
|
||||
}
|
||||
}
|
||||
},
|
||||
define: {
|
||||
__PROXY_LIST__: JSON.stringify(proxy)
|
||||
},
|
||||
build: {
|
||||
sourcemap: false,
|
||||
polyfillDynamicImport: false // 必须为false
|
||||
|
Loading…
Reference in New Issue
Block a user