From 573efe6cd3fd05cafe1f56e31b2e34f3c58ff43f Mon Sep 17 00:00:00 2001 From: yuyang Date: Wed, 28 Dec 2022 15:12:28 +0800 Subject: [PATCH] fix: site path and use history router (#382) --- .env.site | 3 +++ package.json | 1 + src/config/proxy.ts | 6 ++++++ src/router/index.ts | 7 +++++-- 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .env.site diff --git a/.env.site b/.env.site new file mode 100644 index 0000000..c017250 --- /dev/null +++ b/.env.site @@ -0,0 +1,3 @@ +VITE_SOME_KEY=123 +# 打包路径 根据项目不同按需配置 +VITE_BASE_URL = https://static.tdesign.tencent.com/starter/vue-next/ \ No newline at end of file diff --git a/package.json b/package.json index ccd51c8..92cb3d6 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dev:linux": "vite --mode development", "build:test": "vite build --mode test", "build": "vue-tsc --noEmit && vite build --mode release", + "build:site": "vue-tsc --noEmit && vite build --mode site", "preview": "vite preview", "lint": "eslint --ext .vue,.js,.jsx,.ts,.tsx ./ --max-warnings 0", "lint:fix": "eslint --ext .vue,.js,jsx,.ts,.tsx ./ --max-warnings 0 --fix", diff --git a/src/config/proxy.ts b/src/config/proxy.ts index 80d6ae1..3218a38 100644 --- a/src/config/proxy.ts +++ b/src/config/proxy.ts @@ -18,4 +18,10 @@ export default { // 正式环境 cdn 路径 cdn: '', }, + site: { + // TDesign部署特殊需要 与release功能一致 + host: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com', + // 正式环境 cdn 路径 + cdn: '', + }, }; diff --git a/src/router/index.ts b/src/router/index.ts index eb14bbf..4d26430 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,8 @@ -import { useRoute, createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'; +import { useRoute, createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import uniq from 'lodash/uniq'; +const env = import.meta.env.MODE || 'development'; + // 自动导入modules文件夹下所有ts文件 const modules = import.meta.globEager('./modules/**/*.ts'); @@ -8,6 +10,7 @@ const modules = import.meta.globEager('./modules/**/*.ts'); const routeModuleList: Array = []; Object.keys(modules).forEach((key) => { + // @ts-ignore const mod = modules[key].default || {}; const modList = Array.isArray(mod) ? [...mod] : [mod]; routeModuleList.push(...modList); @@ -70,7 +73,7 @@ export const getActive = (maxLevel = 3): string => { }; const router = createRouter({ - history: createWebHashHistory(), + history: createWebHistory(env === 'site' ? '/starter/vue-next/' : null), routes: allRoutes, scrollBehavior() { return {