初始化

This commit is contained in:
aixianling
2021-12-14 18:36:19 +08:00
parent 9afa4101b6
commit a8dff862d2
327 changed files with 88702 additions and 0 deletions

45
packages/index.js Normal file
View File

@@ -0,0 +1,45 @@
// 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
/**
*
* @param Vue 外部接入Vue
* @param params showList:打印加载的应用;apps:加载的应用文件名数组
*/
import core from './core.import'
const install = function (Vue, params) {
if (install.installed) return
// 遍历注册全局组件
let apps = []
let contexts = require.context('.', true, /\.(\/.+)\/App[^\/]+\.vue$/)
if (contexts) {
contexts.keys().map(e => {
if (contexts(e).default) {
if (params?.apps) {
if (params?.apps.includes(contexts(e).default.name)) {
apps.push(contexts(e).default)
Vue.component(contexts(e).default.name, contexts(e).default)
}
} else {
apps.push(contexts(e).default)
Vue.component(contexts(e).default.name, contexts(e).default)
}
}
})
!!params?.showList && console.log(apps.map(e => e.name))
}
core?.map(app => {
apps.push(app.component)
Vue.component(app.name, app.component)
})
return Promise.resolve(apps)
}
// 判断是否是直接引入文件
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue)
}
export default {
// 导出的对象必须具有 install才能被 Vue.use() 方法安装
install
}