How to config vuepress to your project.
- create
.vuepressfolder. - Create
config.jsfile - Add below snippet in
config.js.
const readPkgUp = require('read-pkg-up');
const pkgjson = (readPkgUp.sync()).pkg;
module.exports = {
title: pkgjson.title,
description: pkgjson.description,
base: '/PROJECT_URL/',
themeConfig: {
search: true,
navbar: true,
nav: [{
text: 'Home',
link: '/'
},
{
text: 'Github',
link: 'GITHUB_REPO_LINK'
},
],
sidebar: [
['/', 'Tabe of contents']
], // Assumes GitHub. Can also be a full GitLab url.
repo: '<REPO_URL>',
// Customising the header label
// Defaults to "GitHub"/"GitLab"/"Bitbucket" depending on `themeConfig.repo`
repoLabel: 'Contribute!',
// if your docs are in a different repo from your main project:
docsRepo: '<DOCS_REPO_URL>',
// if your docs are not at the root of the repo:
docsDir: 'docs',
// if your docs are in a specific branch (defaults to 'master'):
docsBranch: '<DOCS_BRACH>',
}
};- Create docs folder. (optional)
- Create
doc-gen.jsand add below snippet.
const path = require('path')
const shell = require('shelljs');
const join = path.join;
const src = __dirname;
const dist = join(__dirname, 'docs');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
shell.rm('-rf', 'docs');
shell.mkdir('-p', join(src, 'docs'));
shell.cp('-R', join(src, '.vuepress'), join(dist, '.vuepress'));
shell.cp('-R', join(src, 'README.md'), join(dist, 'README.md'));
// copy folder if needed
shell.echo('Docs re-created');
if (process.argv[2] === 'prod') {
shell.exec('npm run docs:build', {
async: true
});
} else {
shell.exec('npm run docs:dev', {
async: true
});
}- Create a
deploy.shfile in root.
#! /usr/bin/env sh
# abort on errors
set -e
# generate docs
npm run docs:gen prod
# build
npm run docs:build
# Copy README.md to dist
cp README.md docs/.vuepress/dist
# navigate into the build output directory
cd docs/.vuepress/dist
# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
git push -f <PROJECT_GITHUB_URL> master:gh-pages
cd -- Add scripts in package.json.
"start": "nodemon node doc-gen.js",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"deploy": "deploy.sh"- Add below
devdependences.
"nodemon": "^1.18.3",
"read-pkg-up": "^4.0.0",
"shelljs": "^0.8.2",
"vuepress": "^0.14.1"