Guide
1. Init VuePress V2 Repo
Initialize your project
git init yarn initInstall VuePress locally
yarn add -D vuepress@nextAdd some scripts to
package.json, set source code dir assrc{ "scripts": { "dev": "vuepress dev src", "build": "vuepress build src" } }Add the default temp and cache directory to
.gitignorefile (Warning: this file must be UTF-8 or ASCII to work correctly)echo 'node_modules' >> .gitignore echo '.temp' >> .gitignore echo '.cache' >> .gitignoreCreate your first document
mkdir docs mkdir src echo '# Hello VuePress' > src/README.md
2. Config NavBar and SideBar
Add config file at
src/.vuepress/config.jsWarning:basemust be set to the repo name.destshould be set to the output folder
import { defineUserConfig } from 'vuepress' export default defineUserConfig({ base: '/ziyu_zhou_personal_website/', dest: './docs', lang: 'en-US', title: 'Hello VuePress', description: 'Just playing around', })Use default theme
import { defaultTheme } from 'vuepress' export default { theme: defaultTheme({ // default theme config navbar: [ { text: 'Home', link: '/', }, ], }), }Add Nav Bar Tutorial
export default { theme: defaultTheme({ navbar: [ // NavbarItem { text: 'Foo', link: '/foo/', }, // NavbarGroup { text: 'Group', children: ['/group/foo.md', '/group/bar.md'],}, // string - page file path '/bar/README.md', ], }), }My config
export default { theme: defaultTheme({ navbar: [ { text: 'Home', link: '/', }, { text: 'About', link: '/about/' }, { text: 'Projects', link: '/projects/' }, { text: 'Guide', link: '/guide/' }, { text: 'GitHub', link: 'https://github.com/zzyBen' }, ], }), }Add Side Bar Tutorial
export default { theme: defaultTheme({ // sidebar object // pages under different sub paths will use different sidebar sidebar: { '/guide/': [ { text: 'Guide', children: ['/guide/README.md', '/guide/getting-started.md'], }, ], '/reference/': [ { text: 'Reference', children: ['/reference/cli.md', '/reference/config.md'], }, ], }, }), }My config
export default { theme: defaultTheme({ sidebar: { '/guide/': [ { text: 'Guide', children: ['/guide/README.md', '/guide/getting-started.md'], }, ], }, }), }
3. Add original Harry Porter template
Add npm
styluspackageyarn add -D stylusCopy the folders under ``.
|-- .vuepress |-- components |-- public |-- stylesWarning:
stylein VuePress V2 must be set in.vuepress/styles/index.scss.
Register components
yarn add -D @vuepress/plugin-register-components@nextTutorial
import { registerComponentsPlugin } from '@vuepress/plugin-register-components' import { getDirname, path } from '@vuepress/utils' const __dirname = getDirname(import.meta.url) export default { plugins: [ registerComponentsPlugin({ // options componentsDir: path.resolve(__dirname, './components'), }), ], }