mirror of
https://github.com/cool-team-official/cool-admin-vue.git
synced 2025-12-15 07:27:54 +00:00
添加代理 __PROXY_LIST__
This commit is contained in:
parent
98b7a9228f
commit
ab623bf1f0
@ -1,5 +1,7 @@
|
|||||||
import { isObject } from "../utils";
|
import { isObject } from "../utils";
|
||||||
|
|
||||||
|
console.log(__PROXY_LIST__);
|
||||||
|
|
||||||
export function Permission(value: string) {
|
export function Permission(value: string) {
|
||||||
return function (target: any, key: any, descriptor: any) {
|
return function (target: any, key: any, descriptor: any) {
|
||||||
if (!target.permission) {
|
if (!target.permission) {
|
||||||
@ -26,13 +28,18 @@ export function Service(value: any) {
|
|||||||
// 复杂项
|
// 复杂项
|
||||||
if (isObject(value)) {
|
if (isObject(value)) {
|
||||||
const { proxy, namespace, url, mock } = value;
|
const { proxy, namespace, url, mock } = value;
|
||||||
|
const item = __PROXY_LIST__[proxy];
|
||||||
|
|
||||||
|
if (proxy && !item) {
|
||||||
|
console.error(`${proxy} 指向的地址不存在!`);
|
||||||
|
}
|
||||||
|
|
||||||
target.prototype.namespace = namespace;
|
target.prototype.namespace = namespace;
|
||||||
target.prototype.mock = mock;
|
target.prototype.mock = mock;
|
||||||
|
|
||||||
if (proxy) {
|
if (proxy) {
|
||||||
target.prototype.proxy = 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;
|
const Mock: any;
|
||||||
export default Mock;
|
export default Mock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare const __PROXY_LIST__: any[];
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import type { UserConfig } from "vite";
|
import { UserConfig } from "vite";
|
||||||
import vue from "@vitejs/plugin-vue";
|
import vue from "@vitejs/plugin-vue";
|
||||||
import vueJsx from "@vitejs/plugin-vue-jsx";
|
import vueJsx from "@vitejs/plugin-vue-jsx";
|
||||||
import viteCompression from "vite-plugin-compression";
|
import viteCompression from "vite-plugin-compression";
|
||||||
@ -13,6 +13,21 @@ function resolve(dir: string) {
|
|||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
|
|
||||||
export default (): UserConfig => {
|
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 {
|
return {
|
||||||
base: "/",
|
base: "/",
|
||||||
plugins: [vue(), viteCompression(), Components(), vueJsx(), svgBuilder("./src/icons/svg/")],
|
plugins: [vue(), viteCompression(), Components(), vueJsx(), svgBuilder("./src/icons/svg/")],
|
||||||
@ -32,23 +47,14 @@ export default (): UserConfig => {
|
|||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
port: 9000,
|
port: 9000,
|
||||||
|
proxy,
|
||||||
hmr: {
|
hmr: {
|
||||||
overlay: true
|
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: {
|
build: {
|
||||||
sourcemap: false,
|
sourcemap: false,
|
||||||
polyfillDynamicImport: false // 必须为false
|
polyfillDynamicImport: false // 必须为false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user