feat: 重构插件初始化逻辑,简化应用启动流程并添加调试工具支持
This commit is contained in:
17
src/main.ts
17
src/main.ts
@ -1,19 +1,6 @@
|
|||||||
import './styles';
|
import './styles';
|
||||||
|
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
|
import { setupPlugins } from './plugins';
|
||||||
|
|
||||||
async function init() {
|
setupPlugins(createApp(App)).mount('#app');
|
||||||
const app = createApp(App);
|
|
||||||
{
|
|
||||||
// https://github.com/antfu-collective/vitesse/blob/47618e72dfba76c77b9b85b94784d739e35c492b/src/modules/README.md
|
|
||||||
type UserPluginContext = { app: import('vue').App<Element> };
|
|
||||||
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();
|
|
||||||
|
@ -16,4 +16,17 @@ export function install({ app }: { app: import('vue').App<Element> }) {
|
|||||||
// 2. 显示全局错误提示
|
// 2. 显示全局错误提示
|
||||||
// 3. 进行错误分析和处理
|
// 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(); */
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
export function install() {
|
// https://github.com/antfu-collective/vitesse/blob/47618e72dfba76c77b9b85b94784d739e35c492b/src/modules/README.md
|
||||||
if (import.meta.env.MODE === 'development' && '1' === ('2' as never)) {
|
type UserPluginContext = { app: import('vue').App<Element> };
|
||||||
// TODO: https://github.com/hu3dao/vite-plugin-debug/
|
type UserPlugin = (ctx: UserPluginContext) => void;
|
||||||
// https://eruda.liriliri.io/zh/docs/#快速上手
|
|
||||||
import('eruda').then(({ default: eruda }) => {
|
export function setupPlugins(app: import('vue').App) {
|
||||||
eruda.init({
|
console.group('Setup Plugins');
|
||||||
defaults: {
|
const modules = import.meta.glob<{ install: UserPlugin }>('./*.ts', { eager: true });
|
||||||
transparency: 0.9,
|
for (const path in modules) {
|
||||||
},
|
modules[path].install?.({ app });
|
||||||
});
|
if (modules[path].install !== undefined) {
|
||||||
/* eruda.show(); */
|
const moduleName = path.replace(/\.\/(.*)\.ts/, '$1');
|
||||||
});
|
console.debug(`%c✔ ${moduleName}`, 'color: #07a');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
console.groupEnd();
|
||||||
|
return app;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user