build(projects): 添加构建打包的不同环境配置

This commit is contained in:
Soybean 2021-09-01 18:29:34 +08:00
parent 78a28a4576
commit ef57d9e6a9
3 changed files with 9 additions and 2 deletions

1
.env.vercel Normal file
View File

@ -0,0 +1 @@
VITE_HTTP_ENV=VERCEL

View File

@ -3,7 +3,11 @@
"version": "1.0.0",
"scripts": {
"dev": "vite",
"dev:prod": "vite --mode production",
"dev:vercel": "vite --mode vercel",
"build": "vue-tsc --noEmit --skipLibCheck && vite build",
"build:test": "vue-tsc --noEmit --skipLibCheck && vite build --mode development",
"build:vercel": "vue-tsc --noEmit --skipLibCheck && vite build --mode vercel",
"serve": "vite preview",
"lint": "eslint ./src --ext .vue,.js,jsx,.ts,tsx",
"lint:fix": "eslint --fix ./src --ext .vue,.js,jsx,.ts,tsx",

View File

@ -1,4 +1,4 @@
import { createRouter, createWebHistory } from 'vue-router';
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import type { App } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { customRoutes } from './routes';
@ -6,8 +6,10 @@ import createRouterGuide from './permission';
const routes: Array<RouteRecordRaw> = [...customRoutes];
const isVercel = import.meta.env.VITE_HTTP_ENV === 'VERCEL';
export const router = createRouter({
history: createWebHistory(),
history: isVercel ? createWebHashHistory() : createWebHistory(),
routes
});