diff --git a/src/main.ts b/src/main.ts index 71937df..23cc9f1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,11 +1,11 @@ import { createApp } from 'vue' -import App from './App.vue' -import router from './router' -import store from './store' -import { AppConfig } from './config/app' +import App from '@/App.vue' +import router from '@/router' +import store from '@/store' +import { AppConfig } from '@/config/app' -import { loadAtdComponent } from '@/plugins/antd' -import { registeGlobalComponent } from './components/index' +import { loadAllPlugins } from '@/plugins' +import { registeGlobalComponent } from '@/components/index' /** 导入第三方插件 */ import '@/plugins' @@ -14,8 +14,8 @@ import '@/plugins' const app: ReturnType = createApp(App) app.config.globalProperties = AppConfig -/** 手动注册 antd-vue 组件 */ -loadAtdComponent(app) +/** 加载所有 Plugins */ +loadAllPlugins(app) /** 自动注册全局组件 */ registeGlobalComponent(app) diff --git a/src/plugins/antd.ts b/src/plugins/antd.ts index 79f55d7..b5dc8bf 100644 --- a/src/plugins/antd.ts +++ b/src/plugins/antd.ts @@ -4,10 +4,10 @@ import { createApp } from 'vue' /** * @description 手动注册 antd-vue 组件,达到按需加载目的 * @description Automatically register components under Button, such as Button.Group - * @param {ReturnType} app 整个应用的实例 + * @param {ReturnType} app 整个应用的实例 * @returns void */ -export function loadAtdComponent(app: ReturnType) { +export default function loadComponent(app: ReturnType) { app.use(Button) app.use(Card) app.use(Row) diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 3c85c33..bd17476 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -1 +1,12 @@ -/** 在此处统一导出插件,保持入口文件简介 */ +import { createApp } from 'vue' + +/** + * @description 加载所有 Plugins + * @param {ReturnType} app 整个应用的实例 + */ +export function loadAllPlugins(app: ReturnType) { + const files = require.context('.', true, /\.ts$/) + files.keys().forEach((key) => { + if (key !== './index.ts') files(key).default(app) + }) +}