###### tags: `Vue` `sh deploy.sh` # Vue CLI 使用sh deploy.sh指令上傳到github page ## 1.到vue.config.js修改路徑 如下圖原本的路徑為github的repository ![](https://i.imgur.com/Ihh71T7.jpg) 修改為下圖 ![](https://i.imgur.com/vCDsOgG.jpg) ## 2.增加CMANE檔案 放置的位置為public 如下圖 ![](https://i.imgur.com/kry7s2B.jpg) CNAME的內容如為 vue-eshop.chun-chia.site 也就是子網域加主網域最後是頂級域 ## 3.先新增一個deploy.sh的當案 如下圖,與scr同一層 ![](https://i.imgur.com/Mwv6zDh.jpg) 檔案內容為 ``` #!/usr/bin/env sh # 当发生错误时中止脚本 set -e # 构建 npm run build # cd 到构建输出的目录下 cd dist # 部署到自定义域域名 # echo 'www.example.com' > CNAME git init git add -A git commit -m 'deploy' # 部署到 https://<USERNAME>.github.io # git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master # 部署到 https://<USERNAME>.github.io/<REPO> git push -f git@github.com:a121515222/Vue-seventh-week.git master:gh-pages cd - ``` 記得要調整github,reppository的位置 master看情況可以改成main。 ## 4.在push完之後,就可以在git bash中使用指令上傳 注意要在git bash這個終端機使用sh deploy.sh指令, 不然會無法使用。