refactor(projects): 代码优化
This commit is contained in:
parent
da407b6653
commit
b60db89801
@ -1 +1 @@
|
||||
VITE_HTTP_PROXY=true
|
||||
VITE_HTTP_PROXY=1
|
||||
|
@ -1,6 +1,6 @@
|
||||
VITE_VISUALIZER=false
|
||||
VITE_VISUALIZER=0
|
||||
|
||||
VITE_COMPRESS=false
|
||||
VITE_COMPRESS=0
|
||||
|
||||
# gzip | brotliCompress | deflate | deflateRaw
|
||||
VITE_COMPRESS_TYPE=gzip
|
||||
|
@ -14,10 +14,10 @@ import compress from './compress';
|
||||
export function setupVitePlugins(viteEnv: ImportMetaEnv): (PluginOption | PluginOption[])[] {
|
||||
const plugins = [...vue, html(viteEnv), ...unplugin, unocss, mock];
|
||||
|
||||
if (viteEnv.VITE_VISUALIZER === 'true') {
|
||||
if (viteEnv.VITE_VISUALIZER === '1') {
|
||||
plugins.push(visualizer);
|
||||
}
|
||||
if (viteEnv.VITE_COMPRESS === 'true') {
|
||||
if (viteEnv.VITE_COMPRESS === '1') {
|
||||
plugins.push(compress(viteEnv));
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
"build": "npm run typecheck && cross-env VITE_ENV_TYPE=prod vite build",
|
||||
"build:dev": "npm run typecheck && cross-env VITE_ENV_TYPE=dev vite build",
|
||||
"build:test": "npm run typecheck && cross-env VITE_ENV_TYPE=test vite build",
|
||||
"build:vercel": "cross-env VITE_HASH_ROUTE=true vite build",
|
||||
"build:vercel": "cross-env VITE_HASH_ROUTE=1 VITE_VERCEL=1 vite build",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "vue-tsc --noEmit --skipLibCheck",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
|
||||
|
BIN
src/assets/fonts/aguazyuan-bold.ttf
Normal file
BIN
src/assets/fonts/aguazyuan-bold.ttf
Normal file
Binary file not shown.
BIN
src/assets/fonts/aguazyuan-light.ttf
Normal file
BIN
src/assets/fonts/aguazyuan-light.ttf
Normal file
Binary file not shown.
BIN
src/assets/fonts/aguazyuan-regular.ttf
Normal file
BIN
src/assets/fonts/aguazyuan-regular.ttf
Normal file
Binary file not shown.
@ -7,7 +7,7 @@ interface DemoContext {
|
||||
setCounts: (count: number) => void;
|
||||
}
|
||||
|
||||
const { useProvide: useDemoProvider, useInject: useDemoInject } = useContext<DemoContext>();
|
||||
const { useProvide: useDemoProvide, useInject: useDemoInject } = useContext<DemoContext>();
|
||||
|
||||
export function useDemoContext() {
|
||||
const counts = ref(0);
|
||||
@ -21,12 +21,12 @@ export function useDemoContext() {
|
||||
setCounts
|
||||
};
|
||||
|
||||
function useProvider() {
|
||||
useDemoProvider(demoContext);
|
||||
function useProvide() {
|
||||
useDemoProvide(demoContext);
|
||||
}
|
||||
|
||||
return {
|
||||
useProvider,
|
||||
useProvide,
|
||||
useInject: useDemoInject
|
||||
};
|
||||
}
|
||||
@ -34,8 +34,8 @@ export function useDemoContext() {
|
||||
// 示例用法: A.vue为父组件, B.vue为子孙组件 C.vue为子孙组件
|
||||
// A.vue
|
||||
// import { useDemoContext } from '@/context';
|
||||
// const { useProvider } = useDemoContext();
|
||||
// useProvider();
|
||||
// const { useProvide } = useDemoContext();
|
||||
// useProvide();
|
||||
|
||||
// B.vue 和 C.vue : 共享状态 counts
|
||||
// import { useDemoContext } from '@/context';
|
||||
|
@ -12,7 +12,7 @@
|
||||
<full-screen />
|
||||
<theme-mode />
|
||||
<system-message />
|
||||
<setting-button v-if="isProd" />
|
||||
<setting-button v-if="showButton" />
|
||||
<user-avatar />
|
||||
</div>
|
||||
</dark-mode-container>
|
||||
@ -47,7 +47,7 @@ defineProps<Props>();
|
||||
|
||||
const theme = useThemeStore();
|
||||
|
||||
const isProd = import.meta.env.PROD;
|
||||
const showButton = import.meta.env.PROD && import.meta.env.VITE_VERCEL !== '1';
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
@ -9,7 +9,7 @@
|
||||
<theme-config />
|
||||
</n-drawer-content>
|
||||
</n-drawer>
|
||||
<drawer-button v-if="isDev" />
|
||||
<drawer-button v-if="showButton" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@ -18,7 +18,7 @@ import { DrawerButton, DarkMode, LayoutMode, ThemeColorSelect, PageFunc, PageVie
|
||||
|
||||
const app = useAppStore();
|
||||
|
||||
const isDev = import.meta.env.DEV;
|
||||
const showButton = import.meta.env.DEV || import.meta.env.VITE_VERCEL === '1';
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -5,10 +5,10 @@ import { constantRoutes } from './routes';
|
||||
import { scrollBehavior } from './helpers';
|
||||
import { createRouterGuard } from './guard';
|
||||
|
||||
const { VITE_HASH_ROUTE = 'false', VITE_BASE_URL } = import.meta.env;
|
||||
const { VITE_HASH_ROUTE = '0', VITE_BASE_URL } = import.meta.env;
|
||||
|
||||
export const router = createRouter({
|
||||
history: VITE_HASH_ROUTE === 'true' ? createWebHashHistory(VITE_BASE_URL) : createWebHistory(VITE_BASE_URL),
|
||||
history: VITE_HASH_ROUTE === '1' ? createWebHashHistory(VITE_BASE_URL) : createWebHistory(VITE_BASE_URL),
|
||||
routes: transformAuthRoutesToVueRoutes(constantRoutes),
|
||||
scrollBehavior
|
||||
});
|
||||
|
@ -2,7 +2,7 @@ import { getEnvConfig } from '~/.env-config';
|
||||
import { createRequest } from './request';
|
||||
|
||||
const envConfig = getEnvConfig(import.meta.env);
|
||||
const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === 'true';
|
||||
const isHttpProxy = import.meta.env.VITE_HTTP_PROXY === '1';
|
||||
|
||||
export const request = createRequest({ baseURL: isHttpProxy ? envConfig.proxy : envConfig.url });
|
||||
|
||||
|
12
src/typings/env.d.ts
vendored
12
src/typings/env.d.ts
vendored
@ -30,19 +30,21 @@ interface ImportMetaEnv {
|
||||
*/
|
||||
readonly VITE_AUTH_ROUTE_MODE: 'static' | 'dynamic';
|
||||
/** 路由首页的路径 */
|
||||
readonly VITE_ROUTE_HOME_PATH: Exclude<AuthRoute.RoutePath, '/not-found-page' | '/:pathMatch(.*)*'>;
|
||||
readonly VITE_ROUTE_HOME_PATH: Exclude<AuthRoute.RoutePath, '/' | '/not-found-page' | '/:pathMatch(.*)*'>;
|
||||
/** vite环境类型 */
|
||||
readonly VITE_ENV_TYPE?: EnvType;
|
||||
/** 开启请求代理 */
|
||||
readonly VITE_HTTP_PROXY?: 'true' | 'false';
|
||||
readonly VITE_HTTP_PROXY?: '1' | '0';
|
||||
/** 是否开启打包文件大小结果分析 */
|
||||
readonly VITE_VISUALIZER?: 'true' | 'false';
|
||||
readonly VITE_VISUALIZER?: '1' | '0';
|
||||
/** 是否开启打包压缩 */
|
||||
readonly VITE_COMPRESS?: 'true' | 'false';
|
||||
readonly VITE_COMPRESS?: '1' | '0';
|
||||
/** 压缩算法类型 */
|
||||
readonly VITE_COMPRESS_TYPE?: 'gzip' | 'brotliCompress' | 'deflate' | 'deflateRaw';
|
||||
/** hash路由模式 */
|
||||
readonly VITE_HASH_ROUTE?: 'true' | 'false';
|
||||
readonly VITE_HASH_ROUTE?: '1' | '0';
|
||||
/** 是否是部署的vercel */
|
||||
readonly VITE_VERCEL?: '1' | '0';
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
|
5
src/typings/system.d.ts
vendored
5
src/typings/system.d.ts
vendored
@ -21,11 +21,6 @@ declare namespace EnumType {
|
||||
|
||||
/** 请求的相关类型 */
|
||||
declare namespace Service {
|
||||
/** 请求环境类型
|
||||
* - test:测试环境
|
||||
* - prod:正式环境 */
|
||||
type HttpEnv = 'test' | 'prod';
|
||||
|
||||
/**
|
||||
* 请求的错误类型:
|
||||
* - axios: axios错误:网络错误, 请求超时, 默认的兜底错误
|
||||
|
@ -13,8 +13,8 @@
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"],
|
||||
"~/*": ["./*"]
|
||||
"~/*": ["./*"],
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"types": [
|
||||
"vite/client",
|
||||
@ -23,5 +23,5 @@
|
||||
"naive-ui/volar"
|
||||
]
|
||||
},
|
||||
"exclude": ["dist", "node_modules"]
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { defineConfig, presetUno } from 'unocss';
|
||||
|
||||
export default defineConfig({
|
||||
exclude: ['node_modules', '.git', 'dist', 'mock', './stats.html'],
|
||||
exclude: ['node_modules', '.git', '.husky', '.vscode', 'dist', 'public', 'build', 'mock', './stats.html'],
|
||||
presets: [presetUno({ dark: 'class' })],
|
||||
shortcuts: {
|
||||
'wh-full': 'w-full h-full',
|
||||
|
@ -8,7 +8,7 @@ export default defineConfig(configEnv => {
|
||||
const rootPath = getRootPath();
|
||||
const srcPath = getSrcPath();
|
||||
|
||||
const isOpenProxy = viteEnv.VITE_HTTP_PROXY === 'true';
|
||||
const isOpenProxy = viteEnv.VITE_HTTP_PROXY === '1';
|
||||
const envConfig = getEnvConfig(viteEnv);
|
||||
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user