diff --git a/package.json b/package.json index 751c9e23..1eb4d0ef 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "typecheck": "vue-tsc --noEmit", "build": "npm run typecheck && cross-env VITE_HTTP_ENV=prod vite build", "build:test": "npm run typecheck && cross-env VITE_HTTP_ENV=test vite build", + "build:vercel": "npm run typecheck && cross-env VITE_HTTP_ENV=prod VITE_IS_VERCEL=1 vite build", "preview": "vite preview --port 5050", "lint": "eslint --fix ./ --ext .vue,.js,jsx,.ts,tsx", "prepare": "husky install", diff --git a/src/router/index.ts b/src/router/index.ts index 2e318c80..f73d261a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,11 +1,13 @@ import type { App } from 'vue'; -import { createRouter, createWebHistory } from 'vue-router'; +import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'; import { transformAuthRoutesToVueRoutes } from '@/utils'; import { constantRoutes } from './routes'; import { createRouterGuard } from './guard'; +const createHistoryFunc = import.meta.env.VITE_IS_VERCEL === '1' ? createWebHashHistory : createWebHistory; + export const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL), + history: createHistoryFunc(import.meta.env.BASE_URL), routes: transformAuthRoutesToVueRoutes(constantRoutes), scrollBehavior: () => ({ left: 0, top: 0 }) }); diff --git a/src/typings/common/env.d.ts b/src/typings/common/env.d.ts index 637c222e..27e44911 100644 --- a/src/typings/common/env.d.ts +++ b/src/typings/common/env.d.ts @@ -18,6 +18,8 @@ interface ImportMetaEnv { readonly VITE_APP_DESC: string; /** 网路请求环境类型 */ readonly VITE_HTTP_ENV: Service.HttpEnv; + /** 是否是部署vercel */ + readonly VITE_IS_VERCEL?: '1'; } interface ImportMeta {