@@ -21,19 +21,33 @@ exports.pathsToModuleCode = function (files) {
21
21
return code
22
22
}
23
23
24
+ exports . getPageComponentsLoadingFile = function ( pages ) {
25
+ let code = 'const _l = {}\n'
26
+
27
+ code += pages . map ( ( { filepath, key } ) => {
28
+ return `_l['${ key } '] = () => import('${ filepath } ')`
29
+ } ) . join ( '\n' )
30
+
31
+ code += `\n\nexport default function loadComponent(key) {
32
+ return _l[key]()
33
+ }\n`
34
+ return code
35
+ }
36
+
24
37
exports . genRoutesFile = async function ( {
25
38
siteData : { pages } ,
26
39
plugin
27
40
} ) {
28
- function genRoute ( { filepath, path : pagePath , key : componentName } , index ) {
41
+ await writeTemp ( 'components-loader.js' , exports . getPageComponentsLoadingFile ( pages ) )
42
+
43
+ function genRoute ( { path : pagePath , key : componentName } , index ) {
29
44
let code = `
30
45
{
31
46
name: ${ JSON . stringify ( componentName ) } ,
32
47
path: ${ JSON . stringify ( pagePath ) } ,
33
48
component: ThemeLayout,
34
49
beforeEnter: (to, from, next) => {
35
- loadPageComponent("v-6e489b82c1bb8").then(next)
36
- import(${ JSON . stringify ( filepath ) } ).then(comp => {
50
+ loadComponent(${ JSON . stringify ( componentName ) } ).then(comp => {
37
51
Vue.component(${ JSON . stringify ( componentName ) } , comp.default)
38
52
next()
39
53
})
@@ -80,7 +94,8 @@ exports.genRoutesFile = async function ({
80
94
`import Vue from 'vue'\n` +
81
95
`import ThemeLayout from '@themeLayout'\n` +
82
96
`import ThemeNotFound from '@themeNotFound'\n` +
83
- `import { injectMixins, loadPageComponent } from '@app/util'\n` +
97
+ `import { injectMixins } from '@app/util'\n` +
98
+ `import loadComponent from '@temp/components-loader'\n` +
84
99
`import rootMixins from '@temp/root-mixins'\n\n` +
85
100
`injectMixins(ThemeLayout, rootMixins)\n` +
86
101
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
0 commit comments