切换为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
+2 -2
View File
@@ -7,12 +7,12 @@ const routes = [{
{
path: '/init',
name: 'Init',
component: () => import('@/view/init/index')
component: () => import('@/view/init/index.vue')
},
{
path: '/login',
name: 'Login',
component: () => import('@/view/login/index')
component: () => import('@/view/login/index.vue')
}
]
-3
View File
@@ -1,3 +0,0 @@
module.exports = file => () => {
return import ('@/' + file)
}
+19 -2
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]
}