Skip to content

Commit a92ee43

Browse files
committed
feat: 增加热更新脚本
1 parent 593aa88 commit a92ee43

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

fuck-hot-compile.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# 自动安装依赖的热更新脚本
4+
# 使用方式:chmod +x ./fuck-hot-compile.sh && ./fuck-hot-compile.sh
5+
6+
# 检测包管理器并安装依赖
7+
init_project() {
8+
if command -v yarn &> /dev/null; then
9+
echo "使用 yarn 安装依赖..."
10+
yarn install --frozen-lockfile
11+
elif command -v npm &> /dev/null; then
12+
echo "使用 npm 安装依赖..."
13+
npm ci
14+
else
15+
echo "错误:未检测到 yarn 或 npm,请先安装 Node.js"
16+
exit 1
17+
fi
18+
}
19+
20+
# 获取构建命令
21+
detect_build_command() {
22+
if [ -f yarn.lock ]; then
23+
echo "yarn build"
24+
else
25+
echo "npm run build"
26+
fi
27+
}
28+
29+
# ---------- 主流程 ----------
30+
init_project
31+
build_command=$(detect_build_command)
32+
33+
echo "启动热更新监听..."
34+
while true; do
35+
echo "[$(date +'%T')] 开始构建..."
36+
if $build_command; then
37+
echo "[$(date +'%T')] 构建成功 ✅"
38+
else
39+
echo "[$(date +'%T')] 构建失败 ❌,10秒后重试..."
40+
sleep 10
41+
fi
42+
sleep 1
43+
done

0 commit comments

Comments
 (0)