[Doc] optimize markdown dynamic import (#423)

This commit is contained in:
neverland 2018-08-13 19:12:05 +08:00 committed by GitHub
parent a122ba4826
commit b3d2be2e63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 23 additions and 131 deletions

View File

@ -1,5 +0,0 @@
### 请认真写 ISSUE 的标题,会用于生成 change log。
**请确认是需要 *新增功能* 还是 *提交bug* **
** 如果是 bug请提供复现步骤可能的话可以在 [https://jsfiddle.net](https://jsfiddle.net) 或者类似平台上提供一个 demo **

6
.gitignore vendored
View File

@ -4,10 +4,6 @@
.idea
.vscode
node_modules
CHANGELOG-GENERATED.md
project.config.json
assets/icons/build
assets/icons/svg
example/dist
website/dist
docs/dist
example/dist

View File

@ -1,45 +1,5 @@
require('./compiler');
const fs = require('fs');
const path = require('path');
const glob = require('fast-glob');
const serve = require('webpack-serve');
const config = require('./webpack.doc.dev');
const tips = '// This file is auto gererated by build/build-entry.js';
const root = path.join(__dirname, '../');
const join = dir => path.join(root, dir);
// generate webpack entry file for markdown docs
function buildEntry() {
const output = join('docs/src/docs-entry.js');
const getName = fullPath =>
fullPath
.replace(/(\/README)|(\.md)/g, '')
.split('/')
.pop();
const docs = glob
.sync([
join('docs/**/*.md'),
join('packages/**/*.md'),
'!**/node_modules/**'
])
.map(fullPath => {
const name = getName(fullPath);
return `'${name}': () => import('${path.relative(
join('docs/src'),
fullPath
)}')`;
});
const content = `${tips}
export default {
${docs.join(',\n ')}
};
`;
fs.writeFileSync(output, content);
}
buildEntry();
serve({}, { config });

View File

@ -20,7 +20,6 @@ module.exports = {
},
serve: {
open: true,
host: '0.0.0.0',
devMiddleware: {
logLevel: 'warn'
},

0
dist/index.js vendored
View File

View File

@ -6,9 +6,9 @@ const { version } = packageJson;
export default {
header: {
logo: {
version,
image: 'https://img.yzcdn.cn/public_files/2017/12/18/fd78cf6bb5d12e2a119d0576bedfd230.png',
title: 'Vant Weapp',
version,
href: '#/'
},
nav: {
@ -25,15 +25,18 @@ export default {
list: [
{
path: '/intro',
title: '介绍'
title: '介绍',
md: true
},
{
path: '/quickstart',
title: '快速上手'
title: '快速上手',
md: true
},
{
path: '/changelog',
title: '更新日志'
title: '更新日志',
md: true
},
{
path: '/common',

View File

@ -1,27 +0,0 @@
// This file is auto gererated by build/build-entry.js
export default {
'changelog': () => import('../markdown/changelog.md'),
'intro': () => import('../markdown/intro.md'),
'quickstart': () => import('../markdown/quickstart.md'),
'actionsheet': () => import('../../packages/actionsheet/README.md'),
'badge': () => import('../../packages/badge/README.md'),
'button': () => import('../../packages/button/README.md'),
'card': () => import('../../packages/card/README.md'),
'cell': () => import('../../packages/cell/README.md'),
'col': () => import('../../packages/col/README.md'),
'common': () => import('../../packages/common/README.md'),
'field': () => import('../../packages/field/README.md'),
'icon': () => import('../../packages/icon/README.md'),
'loading': () => import('../../packages/loading/README.md'),
'nav-bar': () => import('../../packages/nav-bar/README.md'),
'notice-bar': () => import('../../packages/notice-bar/README.md'),
'notify': () => import('../../packages/notify/README.md'),
'panel': () => import('../../packages/panel/README.md'),
'popup': () => import('../../packages/popup/README.md'),
'search': () => import('../../packages/search/README.md'),
'stepper': () => import('../../packages/stepper/README.md'),
'steps': () => import('../../packages/steps/README.md'),
'switch': () => import('../../packages/switch/README.md'),
'tag': () => import('../../packages/tag/README.md'),
'tree-select': () => import('../../packages/tree-select/README.md')
};

View File

@ -14,7 +14,6 @@ const router = new VueRouter({
router.beforeEach((route, redirect, next) => {
progress.start();
document.title = route.meta.title || document.title;
next();
});
@ -24,11 +23,7 @@ router.afterEach(() => {
syncPath(router.history.current.path);
});
window.vueRouter = router;
if (process.env.NODE_ENV !== 'production') {
Vue.config.productionTip = false;
}
Vue.config.productionTip = false;
new Vue({ // eslint-disable-line
render: h => h(App),

View File

@ -1,6 +1,8 @@
import Vue from 'vue';
import Preview from './Preview.vue';
Vue.config.productionTip = false;
new Vue({
el: '#app',
render: h => h(Preview)

View File

@ -1,11 +1,12 @@
import docConfig from './doc.config';
import componentDocs from './docs-entry';
const registerRoute = () => {
const route = [{
const route = [
{
path: '*',
redirect: to => `/intro`
}];
}
];
const navs = docConfig.nav || [];
@ -19,12 +20,15 @@ const registerRoute = () => {
}
});
function addRoute(page) {
function addRoute(page, isComponent) {
let { path } = page;
if (path) {
path = path.replace('/', '');
const component = componentDocs[`${path}`];
const component = () =>
page.md
? import(`../markdown/${path}.md`)
: import(`../../packages/${path}/README.md`);
if (!component) {
return;

View File

@ -31,7 +31,6 @@
"css-loader": "^1.0.0",
"eslint": "^5.1.0",
"eslint-plugin-vue-libs": "^3.0.0",
"fast-glob": "^2.2.2",
"fast-vue-md-loader": "^1.0.3",
"gh-pages": "^1.2.0",
"gulp": "^3.9.1",

View File

View File

@ -78,17 +78,6 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
dependencies:
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"
"@nodelib/fs.stat@^1.0.1":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"
"@shellscape/koa-send@^4.1.0":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@shellscape/koa-send/-/koa-send-4.1.3.tgz#1a7c8df21f63487e060b7bfd8ed82e1d3c4ae0b0"
@ -1382,10 +1371,6 @@ cache-content-type@^1.0.0:
mime-types "^2.1.18"
ylru "^1.2.0"
call-me-maybe@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
caller-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-0.1.0.tgz#94085ef63581ecd3daa92444a8fe94e82577751f"
@ -2478,17 +2463,6 @@ fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
fast-glob@^2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.2.tgz#71723338ac9b4e0e2fff1d6748a2a13d5ed352bf"
dependencies:
"@mrmlnc/readdir-enhanced" "^2.2.1"
"@nodelib/fs.stat" "^1.0.1"
glob-parent "^3.1.0"
is-glob "^4.0.0"
merge2 "^1.2.1"
micromatch "^3.1.10"
fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@ -2756,10 +2730,6 @@ glob-stream@^3.1.5:
through2 "^0.6.1"
unique-stream "^1.0.0"
glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"
glob-watcher@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/glob-watcher/-/glob-watcher-0.0.6.tgz#b95b4a8df74b39c83298b0c05c978b4d9a3b710b"
@ -4057,11 +4027,7 @@ merge-source-map@^1.1.0:
dependencies:
source-map "^0.6.1"
merge2@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.2.2.tgz#03212e3da8d86c4d8523cebd6318193414f94e34"
micromatch@^3.0.4, micromatch@^3.1.10, micromatch@^3.1.4, micromatch@^3.1.8:
micromatch@^3.0.4, micromatch@^3.1.4, micromatch@^3.1.8:
version "3.1.10"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
dependencies: