提交 3b16c5c3 编写于 作者: U ULIVZ

feat: support spearate "loadComponent" util

上级 b2c54849
......@@ -17,10 +17,3 @@ export function findPageForPath (pages, path) {
frontmatter: {}
}
}
// export function loadPage (key) {
// return import(${JSON.stringify(filepath)}).then(comp => {
// Vue.component(${JSON.stringify(componentName)}, comp.default)
// next()
// })
// }
......@@ -21,19 +21,33 @@ exports.pathsToModuleCode = function (files) {
return code
}
exports.getPageComponentsLoadingFile = function (pages) {
let code = 'const _l = {}\n'
code += pages.map(({ filepath, key }) => {
return `_l['${key}'] = () => import('${filepath}')`
}).join('\n')
code += `\n\nexport default function loadComponent(key) {
return _l[key]()
}\n`
return code
}
exports.genRoutesFile = async function ({
siteData: { pages },
plugin
}) {
function genRoute ({ filepath, path: pagePath, key: componentName }, index) {
await writeTemp('components-loader.js', exports.getPageComponentsLoadingFile(pages))
function genRoute ({ path: pagePath, key: componentName }, index) {
let code = `
{
name: ${JSON.stringify(componentName)},
path: ${JSON.stringify(pagePath)},
component: ThemeLayout,
beforeEnter: (to, from, next) => {
loadPageComponent("v-6e489b82c1bb8").then(next)
import(${JSON.stringify(filepath)}).then(comp => {
loadComponent(${JSON.stringify(componentName)}).then(comp => {
Vue.component(${JSON.stringify(componentName)}, comp.default)
next()
})
......@@ -80,7 +94,8 @@ exports.genRoutesFile = async function ({
`import Vue from 'vue'\n` +
`import ThemeLayout from '@themeLayout'\n` +
`import ThemeNotFound from '@themeNotFound'\n` +
`import { injectMixins, loadPageComponent } from '@app/util'\n` +
`import { injectMixins } from '@app/util'\n` +
`import loadComponent from '@temp/components-loader'\n` +
`import rootMixins from '@temp/root-mixins'\n\n` +
`injectMixins(ThemeLayout, rootMixins)\n` +
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册