Javascript/vue/vuepress/基本
目次
vuepressとは
Markdownのドキュメントジェネレーター
vuepressインストール
npm init npm install -D vuepress mkdir docs
参考:https://qiita.com/kan_dai/items/d7384abd8f6b2ff8c6c6
helloworld
echo "# Hello World" > docs/README.md echo "# Hello hoge" > docs/hoge.md
localhost:8080/hoge でアクセス
ビルドについて
設定準備
package.json を以下のように編集
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "vuepress dev docs",
"build": "vuepress build docs"
}
ビルド(開発用)
$ npm run dev
ttp://localhost:8080/
ビルド(リリース用)
$ npm run build
"sh: vuepress: command not found"エラーが出るとき
npm install -D vuepress
上記を実行
サイトデザインなど変更
設定ファイル
docs/.vuepress/config.js
リンクの仕方
- [タイトル1](setup/README.md)
画像追加
imgタグで表示される

画像ファイル配下へ置く。
docs/.vuepress/public/img/hoge.png
サイドバー
docs/.vuepress/config.js
module.exports = {
title: 'メモ',
themeConfig: {
sidebar: [
'/',
'/hoge',
// ['/hoge', 'ほげほげです'], // タイトルを付けたい場合
]
}
}
無いページが追加されてるとサイドバー全体が表示されなくなる。
参考:https://qiita.com/kan_dai/items/d7384abd8f6b2ff8c6c6
公式参考:https://vuepress.vuejs.org/theme/default-theme-config.html#sidebar
ディープリンクを追加する場合
appの下にprivacyとhelpがある構成
sidebar: [
{
title: 'アプリ', // required
path: "/app",
sidebarDepth: 1, // optional, defaults to 1
children: [
'/privacy',
'/help',
]
},
ディープリンクを追加する場合、その2
appの下にproject1があり、その下にprivacyとhelpがある構成
sidebar: [
{
title: 'アプリ', // required
path: "/app",
sidebarDepth: 1, // optional, defaults to 1
children: [
{
title: "プロジェクト1",
path:"/project1",
children: [
"/privacy",
"/help",
]
},
]
},
グローバルナビ
themeConfigのnavの下に追加
docs/.vuepress/config.js
module.exports = {
themeConfig: {
nav: [
{ text: 'GooglePlay', link: "https://play.google.com/store/apps/details?id=com.example.project" },
{ text: 'AppStore', link: "https://itunes.apple.com/jp/app//id14547sample?mt=8" },
],
ロゴ画像
docs/.vuepress/config.js
module.exports = {
themeConfig: {
logo: '/img/logo.png',
themeConfigの下にlogoを入れる
docs/.vuepress/public/img/logo.png
カスタム変数用意
.vuepress/scripts/string.js
const string = {
example: {
mail: "hoge@example.com"
}
}
export default {
computed: {
$string () {
return string
}
}
}
.vuepress/enhanceApp.js
import strings from "./scripts/string"
export default ({
Vue,
options,
router,
siteData
}) => {
Vue.mixin(strings);
}
example1.md
ver:{{$string.example.mail}}'
トップページ作成
README.md
---
home: true
heroImage: /img/logo.png
actionText: About world
actionLink: /about/
features:
- title: title1
details: hogehoge. hogehoge. hogehoge.
- title: title2
details: hogehoge. hogehoge. hogehoge.
- title: title3
details: hogehoge. hogehoge. hogehoge.
footer: © hoge1.
---
参考:https://www.nxworld.net/services-resource/hello-vuepress.html
headにscript追加
config.js
head: [
['script',{}, `
console.log('helloworld');
`],
['script', { src: 'https://code.jquery.com/jquery-3.6.0.min.js' }]
]
