LoginSignup
3
1

More than 1 year has passed since last update.

Dockerで簡単VuePress環境構築!!

Last updated at Posted at 2022-03-03

VuePressとは?

vue.jsによる静的サイトジェネレータです。
特定のディレクトリにMarkdownファイルを放り込むと、自動的にページを作成してくれます。
ドキュメントの記述に最適化された静的サイト制作ツールです。

環境

いつも通りDockerを使っていきます!

  • macOS Monterey 12.1
  • Docker version 20.10.12
  • Docker Compose version v2.2.3

構成

.
├── README.md
├── docker
│   └── vue-press
│       └── Dockerfile
├── docker-compose.yml
└── documents
    ├── docs
    │   └── README.md
    ├── node_modules
    ├── package.json
    └── yarn.lock

手順

1. Docker環境構築

1-1. docker-compose.yml作成

docker-compose.yml
version: '3.9'

services:
  vue-press:
    build: docker/vue-press
    ports:
      - "8080:8080"
    volumes:
      - ./documents:/documents
    tty: true

1-2. Dockerfile作成

docker/vue-press/Dockerfile
FROM node:16.0.0
WORKDIR /documents

RUN npm install -g npm@8.5.2
RUN npm cache clean -f

1-3. Docker起動

docker-compose.ymlがあるディレクトリにて以下を実行しましょう。

docker-compose up -d

2. VuePressインストール

公式の手順を参考にします。

2-1. コンテナにインスペクション

docker-compose exec vue-press bash

2-2. yarn初期化

yarn init

2-3. VuePressインストール

yarn add -D vuepress

色々と質問されますがこだわりなければ全てEnterでOKです。

※ Git使っている方は、.gitignoreを使ってnode_modulesを無視することをお勧めします。

documents/.gitignore
/node_modules

2-4. ディレクトリ作成

docsディレクトリを作成します。

mkdir docs

2-5. サンプルドキュメント作成

なんでも良いのですが、以下はサンプルです。

documents/docs/REAME.md
# README.mdサンプル
## テスト見出し

この画面が表示されていたら成功です。

### 記述例
~~~md
Hello VuePress!
~~~

2-6. package.jsonの編集

以下のようにscriptsブロックを追記してください。

documents/package.json
{
  "name": "documents",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "vuepress": "^1.9.7"
  },
  "scripts": {
    "docs:dev": "vuepress dev docs",
    "docs:build": "vuepress build docs"
  }
}

2-7. ローカルサーバーの起動

yarn docs:dev

3. 確認

http://localhost:8080にアクセスして確認してみましょう。

スクリーンショット 2022-03-03 17.00.58.png

おまけ

command追加

Docker起動時にパッケージのインストールとローカルサーバーの起動を行うようにします。

docker-compose.yml
version: '3.9'

services:
  vue-press:
    build: docker/vue-press
    ports:
      - "8080:8080"
    volumes:
      - ./documents:/documents
    tty: true
    command: bash -c "yarn install && yarn docs:dev"
3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1