Skip to content

Commit b3d2be2

Browse files
authored
[Doc] optimize markdown dynamic import (youzan#423)
1 parent a122ba4 commit b3d2be2

13 files changed

Lines changed: 23 additions & 131 deletions

File tree

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
.idea
55
.vscode
66
node_modules
7-
CHANGELOG-GENERATED.md
87
project.config.json
9-
assets/icons/build
10-
assets/icons/svg
8+
docs/dist
119
example/dist
12-
website/dist
13-
docs/dist

build/dev.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
11
require('./compiler');
2-
const fs = require('fs');
3-
const path = require('path');
4-
const glob = require('fast-glob');
52
const serve = require('webpack-serve');
63
const config = require('./webpack.doc.dev');
7-
const tips = '// This file is auto gererated by build/build-entry.js';
8-
const root = path.join(__dirname, '../');
9-
const join = dir => path.join(root, dir);
104

11-
// generate webpack entry file for markdown docs
12-
function buildEntry() {
13-
const output = join('docs/src/docs-entry.js');
14-
15-
const getName = fullPath =>
16-
fullPath
17-
.replace(/(\/README)|(\.md)/g, '')
18-
.split('/')
19-
.pop();
20-
21-
const docs = glob
22-
.sync([
23-
join('docs/**/*.md'),
24-
join('packages/**/*.md'),
25-
'!**/node_modules/**'
26-
])
27-
.map(fullPath => {
28-
const name = getName(fullPath);
29-
return `'${name}': () => import('${path.relative(
30-
join('docs/src'),
31-
fullPath
32-
)}')`;
33-
});
34-
35-
const content = `${tips}
36-
export default {
37-
${docs.join(',\n ')}
38-
};
39-
`;
40-
41-
fs.writeFileSync(output, content);
42-
}
43-
44-
buildEntry();
455
serve({}, { config });

build/webpack.doc.dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
},
2121
serve: {
2222
open: true,
23-
host: '0.0.0.0',
2423
devMiddleware: {
2524
logLevel: 'warn'
2625
},

dist/index.js

Whitespace-only changes.

docs/src/doc.config.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const { version } = packageJson;
66
export default {
77
header: {
88
logo: {
9+
version,
910
image: 'https://img.yzcdn.cn/public_files/2017/12/18/fd78cf6bb5d12e2a119d0576bedfd230.png',
1011
title: 'Vant Weapp',
11-
version,
1212
href: '#/'
1313
},
1414
nav: {
@@ -25,15 +25,18 @@ export default {
2525
list: [
2626
{
2727
path: '/intro',
28-
title: '介绍'
28+
title: '介绍',
29+
md: true
2930
},
3031
{
3132
path: '/quickstart',
32-
title: '快速上手'
33+
title: '快速上手',
34+
md: true
3335
},
3436
{
3537
path: '/changelog',
36-
title: '更新日志'
38+
title: '更新日志',
39+
md: true
3740
},
3841
{
3942
path: '/common',

docs/src/docs-entry.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const router = new VueRouter({
1414

1515
router.beforeEach((route, redirect, next) => {
1616
progress.start();
17-
document.title = route.meta.title || document.title;
1817
next();
1918
});
2019

@@ -24,11 +23,7 @@ router.afterEach(() => {
2423
syncPath(router.history.current.path);
2524
});
2625

27-
window.vueRouter = router;
28-
29-
if (process.env.NODE_ENV !== 'production') {
30-
Vue.config.productionTip = false;
31-
}
26+
Vue.config.productionTip = false;
3227

3328
new Vue({ // eslint-disable-line
3429
render: h => h(App),

docs/src/preview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Vue from 'vue';
22
import Preview from './Preview.vue';
33

4+
Vue.config.productionTip = false;
5+
46
new Vue({
57
el: '#app',
68
render: h => h(Preview)

docs/src/router.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import docConfig from './doc.config';
2-
import componentDocs from './docs-entry';
32

43
const registerRoute = () => {
5-
const route = [{
6-
path: '*',
7-
redirect: to => `/intro`
8-
}];
4+
const route = [
5+
{
6+
path: '*',
7+
redirect: to => `/intro`
8+
}
9+
];
910

1011
const navs = docConfig.nav || [];
1112

@@ -19,12 +20,15 @@ const registerRoute = () => {
1920
}
2021
});
2122

22-
function addRoute(page) {
23+
function addRoute(page, isComponent) {
2324
let { path } = page;
2425
if (path) {
2526
path = path.replace('/', '');
2627

27-
const component = componentDocs[`${path}`];
28+
const component = () =>
29+
page.md
30+
? import(`../markdown/${path}.md`)
31+
: import(`../../packages/${path}/README.md`);
2832

2933
if (!component) {
3034
return;

0 commit comments

Comments
 (0)