Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
6f7bff63
V
Vuepress
项目概览
计算机应用开发
/
前端
/
Vuepress
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vuepress
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f7bff63
编写于
4月 11, 2018
作者:
E
Evan You
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid unnecessary reloads
上级
cc8080f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
24 deletion
+32
-24
lib/app/app.js
lib/app/app.js
+2
-7
lib/prepare.js
lib/prepare.js
+30
-17
未找到文件。
lib/app/app.js
浏览文件 @
6f7bff63
...
...
@@ -3,13 +3,8 @@ import Router from 'vue-router'
import
Content
from
'
./Content
'
import
NotFound
from
'
~notFound
'
import
metadataMixin
from
'
./metadataMixin
'
// .temp/siteData.js is a dynamically generated file that:
// 1. registers all *.md pages and *.vue files found in _components as global
// async components;
// 2. exports siteData
// 3. exports routes
import
{
routes
,
siteData
}
from
'
./.temp/siteData
'
import
{
routes
}
from
'
./.temp/routes
'
import
{
siteData
}
from
'
./.temp/siteData
'
Vue
.
use
(
Router
)
...
...
lib/prepare.js
浏览文件 @
6f7bff63
...
...
@@ -8,36 +8,41 @@ const { inferTitle, extractHeaders } = require('./util')
mkdirp
(
tempPath
)
const
tempCache
=
new
Map
()
function
writeTemp
(
file
,
content
)
{
// cache write to avoid hitting the dist if it didn't change
const
cached
=
tempCache
.
get
(
file
)
if
(
cached
!==
content
)
{
fs
.
writeFileSync
(
path
.
join
(
tempPath
,
file
),
content
)
tempCache
.
set
(
file
,
content
)
}
}
module
.
exports
=
async
function
prepare
(
sourceDir
)
{
// 1. load options
const
options
=
await
resolveOptions
(
sourceDir
)
// 2. generate dynamic component registration file
// 2. generate routes & user components registration code
const
routesCode
=
await
genRoutesFile
(
options
)
const
componentCode
=
await
genComponentRegistrationFile
(
options
)
// 3. generate routes
const
routesCode
=
await
genRoutesFile
(
options
)
writeTemp
(
'
routes.js
'
,
[
componentCode
,
routesCode
].
join
(
'
\n\n
'
))
//
4
. generate siteData
//
3
. generate siteData
const
dataCode
=
`export const siteData =
${
JSON
.
stringify
(
options
.
siteData
,
null
,
2
)}
`
writeTemp
(
'
siteData.js
'
,
dataCode
)
fs
.
writeFileSync
(
path
.
join
(
tempPath
,
'
siteData.js
'
),
[
componentCode
,
routesCode
,
dataCode
].
join
(
'
\n\n
'
)
)
// 5. generate basic polyfill if need to support older browsers
// 4. generate basic polyfill if need to support older browsers
let
polyfillCode
=
``
if
(
!
options
.
siteConfig
.
evergreen
)
{
polyfillCode
=
`import 'es6-promise/auto'
if (!Object.assign) Object.assign = require('object-assign')`
}
fs
.
writeFileSync
(
path
.
join
(
tempPath
,
'
polyfill.js
'
)
,
polyfillCode
)
writeTemp
(
'
polyfill.js
'
,
polyfillCode
)
return
options
}
...
...
@@ -63,7 +68,7 @@ async function resolveOptions (sourceDir) {
?
path
.
resolve
(
siteConfig
.
dest
)
:
path
.
resolve
(
sourceDir
,
'
.vuepress/dist
'
),
publicPath
:
siteConfig
.
base
||
'
/
'
,
pageFiles
:
await
globby
([
'
**/*.md
'
,
'
!.vuepress
'
],
{
cwd
:
sourceDir
}
),
pageFiles
:
sort
(
await
globby
([
'
**/*.md
'
,
'
!.vuepress
'
],
{
cwd
:
sourceDir
})
),
pagesData
:
null
,
themePath
:
null
,
notFoundPath
:
null
...
...
@@ -186,7 +191,7 @@ async function resolveComponents (sourceDir) {
if
(
!
fs
.
existsSync
(
componentDir
))
{
return
}
return
await
globby
([
'
**/*.vue
'
],
{
cwd
:
componentDir
}
)
return
sort
(
await
globby
([
'
**/*.vue
'
],
{
cwd
:
componentDir
})
)
}
async
function
genRoutesFile
({
siteData
:
{
pages
},
sourceDir
,
pageFiles
})
{
...
...
@@ -212,3 +217,11 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
`export const routes = [
${
pages
.
map
(
genRoute
).
join
(
'
,
'
)}
\n]`
)
}
function
sort
(
arr
)
{
return
arr
.
sort
((
a
,
b
)
=>
{
if
(
a
<
b
)
return
-
1
if
(
a
>
b
)
return
1
return
0
})
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录