vue 프로젝트를 생성하기 위한 Node.js 와 git은 설치되어 있다고 가정합니다.
추가로 vue cli 설치를 위한 os에 맞는 yarn 최신 버전을 설치합니다.
https://classic.yarnpkg.com/en/docs/install#mac-stable
$ npm install --global yarn
$ yarn --version
$ vue create vue-devops
프로젝트 생성 과정에서 아래와 같은 순서로 선택합니다. (필수: unit Testing, Jest)
생성된 프로젝트로 이동해서 프로젝트를 로컬에서 실행해봅니다.
$ cd vue-devops
$ npm run serve
github에 vue-devops
프로젝트 생성하기
원격 저장소 설정 및 코드 푸쉬
$ git add .
$ git commit -m "init"
$ git remote add origin <github주소>
$ git git push origin master
github Pages 로 배포하기 위한 라이브러리 추가
$ yarn add gh-pages -D
package.json에서 필요한 내용 추가
homepage, script > predeploy, deploy, clean 부분 추가
{
"name": "vue-devops",
"version": "0.1.0",
"private": true,
"homepage": "https://kimyunbin.github.io/vue-devops",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"predeploy": "vue-cli-service build",
"deploy": "gh-pages -d dist",
"clean": "gh-pages-clean",
"test:unit": "vue-cli-service test:unit",
"lint": "vue-cli-ser
}
... 생략
배포용 publicPath 설정
프로젝트 최상단에 vue.config.js
파일 생성 후 작성
module.exports = {
publicPath: "/vue-devops/",
outputDir: "dist"
}
yarn deploy 명령을 실행하면 원격 저장소의 gh-pages 브랜치를 생성해서 푸시
$ yarn deploy
만약 로그인 실패 시 yarn clean
후 재시도
설정 > pages 배포된 주소를 확인한 후 접속
github > actions 탭의 Set up this workflow 클릭
배포 스크립트인 workflow 파일 (deploy.yml) 내용을 다음과 같이 수정합니다.
name: Deployment
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- name: Checkout source code
uses: actions/checkout@master
- name: Set up Node.js
uses: actions/setup-node@master
with:
node-version: 14.x
- name: Install dependencies
run: yarn install
- name: Test unit
run: yarn test:unit
- name: Build page
run: yarn build
env:
NODE_ENV: production
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
변경된 파일을 스테이지에 추가해서 푸쉬 진행