Files
slogan/server/scripts/build_web.sh
T
admin fc56b47406 server: web 静态托管完善 + 联调脚本 + 清理过期工具
- main.go/auth_middleware: web 静态目录托管与 history 回退、Chrome DevTools 探测处理
- 新增 scripts/build_web.sh(缓存判断构建 web)与 scripts/dev.sh(一键构建+启动)
- 删除已过时的 routes.sh(goframe 自动生成 api.json)与 split_db(数据库已拆分完毕)
- docs: 补充联调与测试规范(测试必须用真实用户数据 wenwu901/123456)
2026-08-04 17:15:37 +08:00

42 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 构建 Flutter web 前端(产物 app/build/web,后端 WebStaticDir 直接托管)
# 缓存判断:产物不存在或源码(lib/ pubspec web/)比产物新时重建,否则跳过
# 用法:bash scripts/build_web.sh (在 server/ 下执行)
set -e
cd "$(dirname "${BASH_SOURCE[0]}")/.."
APP_DIR="$(cd ../app && pwd)"
OUT="$APP_DIR/build/web"
if ! command -v flutter >/dev/null 2>&1; then
echo "[build_web] ERROR: 未找到 flutter,请先安装并加入 PATH(或手动构建)"
exit 1
fi
needs_build=0
if [ ! -d "$OUT" ]; then
needs_build=1
elif find "$APP_DIR/lib" "$APP_DIR/pubspec.yaml" "$APP_DIR/pubspec.lock" "$APP_DIR/web" \
-newer "$OUT" -print 2>/dev/null | grep -q .; then
needs_build=1
fi
if [ "$needs_build" -eq 0 ]; then
echo "[build_web] 产物已是最新,跳过构建:$OUT"
exit 0
fi
# 透传测试账号环境变量到前端(AppConfig.testAccount/testPassword--dart-define 覆盖默认 wenwu901/123456
DEFINES=""
if [ -n "$TEST_ACCOUNT" ]; then
DEFINES="$DEFINES --dart-define=TEST_ACCOUNT=$TEST_ACCOUNT"
fi
if [ -n "$TEST_PASSWORD" ]; then
DEFINES="$DEFINES --dart-define=TEST_PASSWORD=$TEST_PASSWORD"
fi
echo "[build_web] 源码有更新,开始构建 Flutter web(首次约 1-3 分钟)..."
cd "$APP_DIR"
flutter build web --release $DEFINES
echo "[build_web] 完成:$OUT"