使用VuePress搭建在线文档网站

0. 在线文档

VuePress官方在线文档

1. 搭建基本环境

  1. # 将 VuePress 作为一个本地依赖安装
  2. npm install -D vuepress
  3. # 新建一个 docs 文件夹
  4. mkdir docs
  5. # 新建一个文件: docs/README.md
  6. echo '# Hello VuePress!' > docs/README.md
  7. # 启动文档项目
  8. npx vuepress dev docs
  9. # 构建静态文件
  10. npx vuepress build docs
  11. |-- docs
  12. |-- .vuepress
  13. |-- config.js
  14. |-- README.md

2. 配置ts教程文档

  1. 整体结构
  1. |-- dist
  2. |-- dics
  3. |-- .vuepress
  4. |-- public
  5. |-- ts-logo.png
  6. |-- config.js
  7. |-- chapter1
  8. |-- 01_初识TS.md
  9. |-- 02_安装TS.md
  10. |-- 03_HelloWorld.md
  11. |-- chapter2
  12. |-- 1_type.md
  13. |-- 2_interface.md
  14. |-- 3_class.md
  15. |-- 4_function.md
  16. |-- 5_generic.md
  17. |-- 6_other.md
  18. |-- chapter3
  19. |-- 01_react.md
  20. |-- 02_vue.md
  21. |-- chapter4
  22. |-- README.md
  23. |-- README.md
  24. |-- package.json
  1. docs/.vuepress/config.js
  1. // 注意: base的值为github仓库的名称
  2. module.exports = {
  3. base: '/ts-study/', /* 基础虚拟路径: */
  4. dest: 'dist', /* 打包文件基础路径, 在命令所在目录下 */
  5. title: 'TypeScript 入门', // 标题
  6. description: '学习使用 TypeScript', // 标题下的描述
  7. themeConfig: { // 主题配置
  8. sidebar: [ // 左侧导航
  9. {
  10. title: '初识 TypeScript', // 标题
  11. collapsable: false, // 下级列表不可折叠
  12. children: [ // 下级列表
  13. 'chapter1/01_初识TS',
  14. 'chapter1/02_安装TS',
  15. 'chapter1/03_HelloWorld'
  16. ]
  17. },
  18. {
  19. title: 'TypeScript 常用语法',
  20. collapsable: false,
  21. children: [
  22. 'chapter2/1_type',
  23. 'chapter2/2_interface',
  24. 'chapter2/3_class',
  25. 'chapter2/4_function',
  26. 'chapter2/5_generic',
  27. ]
  28. },
  29. ]
  30. }
  31. }
  1. docs/README.md
  1. ---
  2. #首页
  3. home: true
  4. # 图标
  5. heroImage: /ts-logo.png
  6. # 按钮文本
  7. actionText: 开始学习 →
  8. # 按钮点击跳转路径
  9. actionLink: /chapter1/01_初识TS
  10. ---
  1. package.json
  1. "scripts": {
  2. "doc:dev": "vuepress dev docs",
  3. "doc:build": "vuepress build docs",
  4. "doc:deploy": "gh-pages -d docs/dist"
  5. }

3. 发布到gitpage

  1. 使用git管理当前项目

  2. 将打包的项目推送到gitpage

  1. # 下载工具包
  2. yarn add -D gh-pages
  3. # 执行打包命令
  4. yarn doc:build
  5. # 执行部署命令
  6. yarn doc:deploy