From b70da8aad4178c45b55f3ce86f8cd81f8cd49325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Wed, 8 Jan 2025 09:35:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E5=BA=94=E7=94=A8=E5=90=AF=E5=8A=A8=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 17 ++--------------- src/plugins/_.ts | 13 +++++++++++++ src/plugins/index.ts | 27 +++++++++++++++------------ 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9ec967b..9b2109d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,19 +1,6 @@ import './styles'; import App from './App.vue'; +import { setupPlugins } from './plugins'; -async function init() { - const app = createApp(App); - { - // https://github.com/antfu-collective/vitesse/blob/47618e72dfba76c77b9b85b94784d739e35c492b/src/modules/README.md - type UserPluginContext = { app: import('vue').App }; - type UserPlugin = (ctx: UserPluginContext) => void; - Object.values(import.meta.glob<{ install: UserPlugin }>('./plugins/*.ts', { eager: true })).forEach((i) => - i.install?.({ app }), - ); - } - - app.mount('#app'); -} - -init(); +setupPlugins(createApp(App)).mount('#app'); diff --git a/src/plugins/_.ts b/src/plugins/_.ts index 6691061..2993e6d 100644 --- a/src/plugins/_.ts +++ b/src/plugins/_.ts @@ -16,4 +16,17 @@ export function install({ app }: { app: import('vue').App }) { // 2. 显示全局错误提示 // 3. 进行错误分析和处理 }; + + if (import.meta.env.MODE === 'development' && '1' === ('2' as never)) { + // TODO: https://github.com/hu3dao/vite-plugin-debug/ + // https://eruda.liriliri.io/zh/docs/#快速上手 + import('eruda').then(({ default: eruda }) => { + eruda.init({ + defaults: { + transparency: 0.9, + }, + }); + /* eruda.show(); */ + }); + } } diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 881de93..6c67653 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1,14 +1,17 @@ -export function install() { - if (import.meta.env.MODE === 'development' && '1' === ('2' as never)) { - // TODO: https://github.com/hu3dao/vite-plugin-debug/ - // https://eruda.liriliri.io/zh/docs/#快速上手 - import('eruda').then(({ default: eruda }) => { - eruda.init({ - defaults: { - transparency: 0.9, - }, - }); - /* eruda.show(); */ - }); +// https://github.com/antfu-collective/vitesse/blob/47618e72dfba76c77b9b85b94784d739e35c492b/src/modules/README.md +type UserPluginContext = { app: import('vue').App }; +type UserPlugin = (ctx: UserPluginContext) => void; + +export function setupPlugins(app: import('vue').App) { + console.group('Setup Plugins'); + const modules = import.meta.glob<{ install: UserPlugin }>('./*.ts', { eager: true }); + for (const path in modules) { + modules[path].install?.({ app }); + if (modules[path].install !== undefined) { + const moduleName = path.replace(/\.\/(.*)\.ts/, '$1'); + console.debug(`%c✔ ${moduleName}`, 'color: #07a'); + } } + console.groupEnd(); + return app; }