From 52dd81dff443cf38a6a5a0c7eabd44c95fd46d7d Mon Sep 17 00:00:00 2001 From: kuangyaxing Date: Fri, 2 Jun 2023 10:45:11 +0800 Subject: [PATCH 1/3] =?UTF-8?q?types:=20=E4=BF=AE=E5=A4=8Dtypescript?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/base-widgets/index.ts | 15 +++++++++++++-- src/packages/container-component/index.ts | 16 ++++++++++++++-- .../components/left-aside/components/index.ts | 11 ++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/packages/base-widgets/index.ts b/src/packages/base-widgets/index.ts index 4e1275b..82f5bc8 100644 --- a/src/packages/base-widgets/index.ts +++ b/src/packages/base-widgets/index.ts @@ -1,12 +1,23 @@ import { VisualEditorComponent } from '@/visual-editor/visual-editor.utils'; -const modules = import.meta.globEager('./*/index.tsx'); +const modules = import.meta.globEager('./*/index.tsx') as Record< + string, + undefined | { default: VisualEditorComponent } | VisualEditorComponent +>; + +type DefaultModule = { default: VisualEditorComponent }; const components: Record = {}; Object.entries(modules).forEach(([key, module]) => { const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1'); - components[name] = module?.default || module; + if (module) { + if (Object.prototype.hasOwnProperty.call(module, 'default')) { + components[name] = (module as DefaultModule).default; + } else { + components[name] = module as VisualEditorComponent; + } + } }); console.log(components, 'base-widgets'); diff --git a/src/packages/container-component/index.ts b/src/packages/container-component/index.ts index 60c123c..35e3bcf 100644 --- a/src/packages/container-component/index.ts +++ b/src/packages/container-component/index.ts @@ -1,12 +1,24 @@ import { VisualEditorComponent } from '@/visual-editor/visual-editor.utils'; -const modules = import.meta.globEager('./*/index.tsx'); +const modules = import.meta.globEager('./*/index.tsx') as Record< + string, + undefined | { default: VisualEditorComponent } | VisualEditorComponent +>; + +type DefaultModule = { default: VisualEditorComponent }; const components: Record = {}; Object.keys(modules).forEach((key: string) => { const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1'); - components[name] = modules[key]?.default || modules[key]; + const module = modules[key]; + if (module) { + if (Object.prototype.hasOwnProperty.call(module, 'default')) { + components[name] = (module as DefaultModule).default; + } else { + components[name] = module as VisualEditorComponent; + } + } }); console.log(components, 'container-component'); diff --git a/src/visual-editor/components/left-aside/components/index.ts b/src/visual-editor/components/left-aside/components/index.ts index 5e85ccd..e1b6397 100644 --- a/src/visual-editor/components/left-aside/components/index.ts +++ b/src/visual-editor/components/left-aside/components/index.ts @@ -1,14 +1,19 @@ import { DefineComponent } from 'vue'; -const modules = import.meta.globEager('./*/index.(tsx|vue)'); +const modules = import.meta.globEager('./*/index.(tsx|vue)') as Record< + string, + undefined | { default: DefineComponent } +>; const components: Record = {}; console.log(modules, '起航'); for (const path in modules) { - const comp = modules[path].default; - components[comp.name || path.split('/')[1]] = comp; + const comp = modules[path]?.default; + if (comp) { + components[comp.name || path.split('/')[1]] = comp; + } } console.log('left-aside components:', components); From 30f8235623f50938679222050ed305a21f285825 Mon Sep 17 00:00:00 2001 From: kuangyaxing Date: Fri, 2 Jun 2023 10:52:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=E5=8D=87=E7=BA=A7vite=E5=88=B0vit?= =?UTF-8?q?e4=E4=BB=A5=E5=8F=8A=E9=85=8D=E5=A5=97=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto-imports.d.ts | 24 ++++++++++++++++++++++-- components.d.ts | 8 +++++--- package.json | 14 +++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/auto-imports.d.ts b/auto-imports.d.ts index cf8e8fa..1627043 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -1,5 +1,8 @@ -// Generated by 'unplugin-auto-import' -export {}; +/* eslint-disable */ +/* prettier-ignore */ +// @ts-nocheck +// Generated by unplugin-auto-import +export {} declare global { const EffectScope: typeof import('vue')['EffectScope']; const computed: typeof import('vue')['computed']; @@ -20,6 +23,8 @@ declare global { const nextTick: typeof import('vue')['nextTick']; const onActivated: typeof import('vue')['onActivated']; const onBeforeMount: typeof import('vue')['onBeforeMount']; + const onBeforeRouteLeave: typeof import('vue-router')['onBeforeRouteLeave']; + const onBeforeRouteUpdate: typeof import('vue-router')['onBeforeRouteUpdate']; const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']; const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']; const onDeactivated: typeof import('vue')['onDeactivated']; @@ -42,11 +47,13 @@ declare global { const toRaw: typeof import('vue')['toRaw']; const toRef: typeof import('vue')['toRef']; const toRefs: typeof import('vue')['toRefs']; + const toValue: typeof import('vue')['toValue']; const triggerRef: typeof import('vue')['triggerRef']; const unref: typeof import('vue')['unref']; const useAttrs: typeof import('vue')['useAttrs']; const useCssModule: typeof import('vue')['useCssModule']; const useCssVars: typeof import('vue')['useCssVars']; + const useLink: typeof import('vue-router')['useLink']; const useRoute: typeof import('vue-router')['useRoute']; const useRouter: typeof import('vue-router')['useRouter']; const useSlots: typeof import('vue')['useSlots']; @@ -55,3 +62,16 @@ declare global { const watchPostEffect: typeof import('vue')['watchPostEffect']; const watchSyncEffect: typeof import('vue')['watchSyncEffect']; } +// for type re-export +declare global { + // @ts-ignore + export type { + Component, + ComponentPublicInstance, + ComputedRef, + InjectionKey, + PropType, + Ref, + VNode, + } from 'vue'; +} diff --git a/components.d.ts b/components.d.ts index 1296c7c..9129b60 100644 --- a/components.d.ts +++ b/components.d.ts @@ -1,7 +1,9 @@ -// generated by unplugin-vue-components -// We suggest you to commit this file into source control +/* eslint-disable */ +/* prettier-ignore */ +// @ts-nocheck +// Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 -import '@vue/runtime-core'; +import '@vue/runtime-core' export {}; diff --git a/package.json b/package.json index 0a5d9ca..2d7af68 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,8 @@ "@types/node": "^18.0.3", "@typescript-eslint/eslint-plugin": "^5.30.5", "@typescript-eslint/parser": "^5.30.5", - "@vitejs/plugin-legacy": "^1.8.2", - "@vitejs/plugin-vue": "^2.3.3", + "@vitejs/plugin-legacy": "^4.0.4", + "@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue-jsx": "^1.3.10", "commitizen": "^4.2.4", "conventional-changelog-cli": "^2.2.2", @@ -89,12 +89,12 @@ "stylelint-order": "^5.0.0", "stylelint-scss": "^4.3.0", "typescript": "^4.7.4", - "unplugin-auto-import": "^0.9.2", - "unplugin-vue-components": "^0.21.1", - "unplugin-vue-define-options": "^0.6.2", - "vite": "2.9.14", + "unplugin-auto-import": "^0.16.4", + "unplugin-vue-components": "^0.25.0", + "unplugin-vue-define-options": "^1.3.7", + "vite": "^4.3.9", "vite-plugin-checker": "^0.4.8", - "vite-plugin-windicss": "^1.8.6", + "vite-plugin-windicss": "^1.9.0", "vue-eslint-parser": "^9.0.3", "vue-tsc": "^0.38.3", "windicss": "^3.5.6" From de08c05b887230bb9dcc5e9549af714a3f610562 Mon Sep 17 00:00:00 2001 From: kuangyaxing Date: Fri, 2 Jun 2023 10:56:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=9C=89=E5=85=B3vite=E7=89=88=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e006b66..6e524b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 基于 Vite2.x + Vue3.x + TypeScript H5 低代码平台 +# 基于 Vite4.x + Vue3.x + TypeScript H5 低代码平台 [![license](https://img.shields.io/github/license/buqiyuan/vite-vue3-lowcode.svg)](LICENSE) @@ -66,7 +66,7 @@ pnpm build ## 技术栈 - 编程语言:[TypeScript 4.x](https://www.typescriptlang.org/zh/) + [JavaScript](https://www.javascript.com/) -- 构建工具:[Vite 2.x](https://cn.vitejs.dev/) +- 构建工具:[Vite 4.x](https://cn.vitejs.dev/) - 前端框架:[Vue 3.x](https://v3.cn.vuejs.org/) - 路由工具:[Vue Router 4.x](https://next.router.vuejs.org/zh/index.html) - 状态管理:[Vuex 4.x](https://next.vuex.vuejs.org/)