Skip to content

Commit d210ec0

Browse files
committed
refactor: use async components to simplify code
1 parent 3b16c5c commit d210ec0

File tree

2 files changed

+3
-27
lines changed

2 files changed

+3
-27
lines changed

lib/prepare/codegen.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,16 @@ exports.pathsToModuleCode = function (files) {
2121
return code
2222
}
2323

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-
3724
exports.genRoutesFile = async function ({
3825
siteData: { pages },
3926
plugin
4027
}) {
41-
await writeTemp('components-loader.js', exports.getPageComponentsLoadingFile(pages))
42-
4328
function genRoute ({ path: pagePath, key: componentName }, index) {
4429
let code = `
4530
{
4631
name: ${JSON.stringify(componentName)},
4732
path: ${JSON.stringify(pagePath)},
48-
component: ThemeLayout,
49-
beforeEnter: (to, from, next) => {
50-
loadComponent(${JSON.stringify(componentName)}).then(comp => {
51-
Vue.component(${JSON.stringify(componentName)}, comp.default)
52-
next()
53-
})
54-
}
33+
component: ThemeLayout
5534
}`
5635

5736
const dncodedPath = decodeURIComponent(pagePath)
@@ -94,11 +73,11 @@ exports.genRoutesFile = async function ({
9473
`import Vue from 'vue'\n` +
9574
`import ThemeLayout from '@themeLayout'\n` +
9675
`import ThemeNotFound from '@themeNotFound'\n` +
97-
`import { injectMixins } from '@app/util'\n` +
98-
`import loadComponent from '@temp/components-loader'\n` +
76+
`import { injectMixins, loadComponent } from '@app/util'\n` +
9977
`import rootMixins from '@temp/root-mixins'\n\n` +
10078
`injectMixins(ThemeLayout, rootMixins)\n` +
10179
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
80+
`${pages.map(({ filepath, key }) => `Vue.component('${key}', () => import('${filepath}'))`).join('\n')}\n\n` +
10281
`export const routes = [${pages.map(genRoute).join(',')}${notFoundRoute}\n]`
10382
)
10483
}

packages/vuepress-translation-comparison/TranslationHelper.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export default {
2020
currentPath: '/'
2121
}
2222
},
23-
created () {
24-
console.log(this.key)
25-
},
2623
computed: {
2724
key () {
2825
return this.currentPage.key

0 commit comments

Comments
 (0)