File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments