Skip to content

Commit

Permalink
build(projects): 添加vercel打包的环境
Browse files Browse the repository at this point in the history
  • Loading branch information
Soybean committed Jan 10, 2022
1 parent a090d39 commit 371fad4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions 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 })
});
Expand Down
2 changes: 2 additions & 0 deletions src/typings/common/env.d.ts
Expand Up @@ -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 {
Expand Down

0 comments on commit 371fad4

Please sign in to comment.