切换为vite模式

This commit is contained in:
piexlmax
2021-09-03 19:20:08 +08:00
parent c94c6c49a8
commit a785f12fb3
6 changed files with 155 additions and 49 deletions

View File

@@ -1,8 +1,10 @@
const _import = require('./_import') // 获取组件的方法
const modules = import.meta.glob('../../view/**/*.vue')
export const asyncRouterHandle = (asyncRouter) => {
asyncRouter.map(item => {
if (item.component) {
item.component = _import(item.component)
item.component = dynamicImport(modules, item.component)
console.log(item.component)
} else {
delete item['component']
}
@@ -11,3 +13,18 @@ export const asyncRouterHandle = (asyncRouter) => {
}
})
}
function dynamicImport(
dynamicViewsModules,
component
) {
const keys = Object.keys(dynamicViewsModules)
const matchKeys = keys.filter((key) => {
let k = key.replace('../../view', '')
const lastIndex = k.lastIndexOf('.')
k = k.substring(0, lastIndex)
return k === component
})
const matchKey = matchKeys[0]
return dynamicViewsModules[matchKey]
}