實現打包,強制將靜態文件推送到倉庫
#!/bin/sh
yarn build
cd dist
git init
echo "正在添加文件..."
git add .
echo -n "正在提交備注...,請填寫備注(可空)"
read remarks
if [ ! -n "$remarks" ]
then
remarks="常規提交"
fi
git commit -m "$remarks"
echo "正在開始提交代碼..."
git remote add origin "https://gitee.com/cjh-1996/home_page.git"
git push -f origin master
exit
實現上傳打包壓縮功能
- 自動上傳git倉庫
- 控制是否打包
- 自動將打包文件壓縮為zip格式
#!/bin/sh
echo "正在添加文件..."
git add .
echo -n "正在提交備注...,請填寫備注(可空)"
read remarks
if [ ! -n "$remarks" ]
then
remarks="常規提交"
fi
git commit -m "$remarks"
echo "正在開始提交代碼..."
git push
echo "代碼提交成功!!!"
echo "是否需要打包,請輸入y/n"
read buid
if [ $buid = "y" ]
then
echo "等待打包中......"
yarn build
else
exit
fi
#自動壓縮
echo "等待壓縮中......"
winrar a dist.zip dist
echo "<<<<<<<<<<<<<<<<<<成功了>>>>>>>>>>>>>>>>>>"
exit
通過修改package.json的script命令 運行腳本
//package.json
"scripts": {
"dev": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"push":"sh ./push.sh", # 關鍵代碼
},
遇到的問題
一 . 在運行yarn push的時候提示sh
非內部命令
原因:
window並沒有自帶bash,如果安裝了git,會附帶bash
通過Everything搜索 bash.exe ,然后復制路徑 ,配置環境變量

然后關閉命令行 重新運行 發現沒有提示錯誤
同理winrar
同樣配置