#!/bin/bash
# 定义项目路径和部署目录
project_path='/www/vue-project'
build_path='/www/build'
# 进入项目目录进行代码更新
cd $project_path
git fetch origin master
new_changes=$(git rev-list HEAD...origin/master --count)
# 判断是否有新的更改
if [ $new_changes -gt 0 ]; then
# 执行代码更新
git pull
# 安装依赖
npm install
# 执行vue编译命令
npm run build
# 将打包文件拷贝到部署目录
# cp -r $project_path/dist/index.html $build_path/
cp -r $project_path/dist/* $build_path/
chmod -R www 755 $build_path/
sudo chown -R www $build_path/
sudo chmod -R 755 $build_path/
# 重启nginx服务器
# systemctl restart nginx
else
# # # 如果没有新的更改,则不进行编译
echo "No changes in git repo"
fi