VuePress

260 阅读1分钟

Ubuntu 安装 node.js

sudo apt update
sudo apt install nodejs 

验证:nodejs --version

安装yarn

在 Ubuntu 系统中不能直接通过 apt 安装,需要先添加 yarn 仓库

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

随后更新 apt 再下载即可。

sudo apt-get update && sudo apt-get install yarn

开始创建第一个文档

  • 创建并进入一个新目录

    mkdir vuepress-starter && cd vuepress-starter

  • 使用你喜欢的包管理器进行初始化

    yarn init # npm init

  • 将 VuePress 安装为本地依赖,不推荐全局安装 VuePress

    yarn add -D vuepress # npm install -D vuepress

  • 创建你的第一篇文档

    mkdir docs && echo '# Hello VuePress' > docs/README.md

  • 在 package.json 中添加一些 scripts

{
  "scripts": {
    "docs:dev": "vuepress dev docs",
    "docs:build": "vuepress build docs"
  }
}
  • 在本地启动服务器

    yarn docs:dev

基本配置

配置文件

在你的文档目录(docs)下创建一个 .vuepress 目录 mkdir .vuepress 一个 VuePress 网站必要的配置文件是 .vuepress/config.js touch config.js 它应该导出一个 JavaScript 对象:

module.exports = {
  title: 'Hello VuePress',
  description: 'Just playing around'
}

运行起 dev server,你应该能看到一个页面,它包含一个页头,里面包含一个标题和一个搜索框。

配置主题

导航栏链接: 你可以通过 themeConfig.nav 增加一些导航栏链接: 修改.vuepress/config.js

// .vuepress/config.js
module.exports = {
  tle: 'Hello VuePress',
  themeConfig: {
    nav: [
      { text: 'Home', link: '/' },
      { text: 'Guide', link: '/guide/' },
      { text: 'External', link: 'https://google.com' },
    ]
  }
}