πŸŽ‡ 1. VuePress μ‹œμž‘ν•˜κΈ°

@JavaPark Β· October 26, 2022 Β· 3 min read

VuePress μ‹œμž‘ν•˜κΈ°

VuePress λ₯Ό μ΄μš©ν•˜μ—¬ TIL 을 μž‘μ„±ν•˜λ €κ³  ν•œλ‹€. VuePress λ₯Ό μ΄μš©ν•˜μ—¬ md νŒŒμΌμ„ html 둜 λ³€ν™˜ν•˜κ³  이λ₯Ό μ„œλΉ„μŠ€ ν•˜λ €κ³  ν•œλ‹€. 그럼 Vuepress λŠ” 무엇인가?

Vuepress λŠ” 무엇?

  1. Vuepress λŠ” Vue.js 둜 κ°œλ°œλ˜μ–΄μ§„ 정적 μ‚¬μ΄νŠΈ 생성기이닀
  2. κΈ°μˆ λ¬Έμ„œ μž‘μ„±μ„ μœ„ν•΄ μ΅œμ ν™”λœ κΈ°λ³Έν…Œλ§ˆλ₯Ό μ œκ³΅ν•΄μ€€λ‹€
  3. Plugin APIλ₯Ό μ œκ³΅ν•΄μ£Όμ–΄ ν”ŒλŸ¬κ·ΈμΈμ„ μ œμž‘ν•˜κ±°λ‚˜ μ μš©ν•  수 μžˆλ‹€. ( Google Analytics, PWA λ₯Ό μ†μ‰½κ²Œ μ μš©κ°€λŠ₯함 )

κΈ°λ³Έ μ„€μΉ˜ 및 λΉŒλ“œ

# global install
$ yarn global add vuepress

# install as a local dependency
$ yarn add -D vuepress

$ mkdir docs

# λ§ˆν¬λ‹€μš΄ νŒŒμΌμ„ μƒμ„±ν•œλ‹€.
$ echo '# Hello VuePress' > docs/README.md

package.json 에 scripts μΆ”κ°€

{
  "scripts": {
    "docs:dev": "vuepress dev docs",
    "docs:build": "vuepress build docs"
  }
}
# Development Mode
$ yarn docs:dev

# build to static files
$ yarn docs:build

Directory Structure

VuePress μ—μ„œ ꢌμž₯λ˜λŠ” κ΅¬μ‘°λŠ” μ•„λž˜μ™€ κ°™λ‹€

.
β”œβ”€β”€ docs
β”‚   β”œβ”€β”€ .vuepress (Optional)
β”‚   β”‚   β”œβ”€β”€ components (Optional)
β”‚   β”‚   β”œβ”€β”€ theme (Optional)
β”‚   β”‚   β”‚   └── Layout.vue
β”‚   β”‚   β”œβ”€β”€ public (Optional)
β”‚   β”‚   β”œβ”€β”€ styles (Optional)
β”‚   β”‚   β”‚   β”œβ”€β”€ index.styl
β”‚   β”‚   β”‚   └── palette.styl
β”‚   β”‚   β”œβ”€β”€ templates (Optional, Danger Zone)
β”‚   β”‚   β”‚   β”œβ”€β”€ dev.html
β”‚   β”‚   β”‚   └── ssr.html
β”‚   β”‚   β”œβ”€β”€ config.js (Optional)
β”‚   β”‚   └── enhanceApp.js (Optional)
β”‚   β”‚ 
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ guide
β”‚   β”‚   └── README.md
β”‚   └── config.md
β”‚ 
└── package.json

:::warning Note μžμ„Έν•œ 사항은 VuePress κ³΅μ‹λ¬Έμ„œ λ₯Ό μ°Έκ³ ν•˜κΈΈ λ°”λž€λ‹€ :::

Default Page Routing

νƒ€κ²Ÿ λ””λ ‰ν† λ¦¬λ‘œ docs λ₯Ό μ‚¬μš©ν•œλ‹€. μ•„λž˜μ˜ λͺ¨λ“  'μƒλŒ€κ²½λ‘œ'λŠ” docs 디렉토리에 μƒλŒ€μ μ΄λ‹€. κΈ°λ³Έ νŽ˜μ΄μ§€ λΌμš°νŒ… κ²½λ‘œλŠ” λ‹€μŒκ³Ό κ°™λ‹€

경둜 νŽ˜μ΄μ§€ λΌμš°νŒ…
/README.md /
/guide/README.md /guide/
/config.md /config.html

Maekdown Extensions

Syntax Highlighting in Code Blocks

input

``` js
export default {
  name: 'MyComponent',
  // ...
}
```

output

export default {
  name: 'MyComponent',
  // ...
}

Line Numbers

You can enable line numbers for each code blocks via config:

module.exports = {
  markdown: {
    lineNumbers: true
  }
}

Deploying

GitHub Pages

  1. docs/.vuepress/config.js 에 base μ„€μ •

https://github.com/<USERNAME>/<REPO> 의 경우 base λŠ” "//" κ°€ 됨

  1. ν”„λ‘œμ νŠΈ 내에 deploy.sh μ„€μ •
#!/usr/bin/env sh

# abort on errors
set -e

# build
npm run docs:build

# 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'

# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master

# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f https://github.com/javapark/javapark.github.io.git master:gh-pages

cd -
  1. main.yaml μ„€μ •
name: Build and Deploy
on: [push]
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@main

    - name: Vuepress deploy
      uses: jenkey2011/vuepress-deploy@1.0.1
      env:
        ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
        BUILD_SCRIPT: yarn && yarn docs:build
        TARGET_BRANCH: gh-pages
        BUILD_DIR: docs/.vuepress/dist

Netlify

  1. Netlify , setup up a new project from GitHub with the following settings:
  • Build Command: vuepress build docs or yarn docs:build or npm run docs:build
  • Publish directory: docs/.vuepress/dist
  1. Hit the deploy button

Ref

@JavaPark
AI μ‹œλŒ€μ˜ 개발자 도ꡬ, μ‹€μ „ κ²½ν—˜μ„ κ³΅μœ ν•©λ‹ˆλ‹€