#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" FRONTEND="$ROOT/frontend" OUT="$ROOT/ios/WordLoop/WordLoop/www" echo ">>> 构建 iOS 内嵌前端" cd "$FRONTEND" if [ ! -d node_modules ]; then npm install --silent fi npm run build:ios rm -rf "$OUT" mkdir -p "$OUT" cp -R dist/* "$OUT/" python3 - <', html) if script: tag = script.group(0) if tag not in html.split("", 1)[-1]: html = html.replace(tag, "", 1) html = html.replace("", f" {tag}\n ", 1) html_path.write_text(html, encoding="utf-8") if len(html) > 20_000: raise SystemExit("index.html 过大,可能仍含内联 JS,会导致 WebKit overflow 崩溃") for block in re.findall(r"", html, re.DOTALL): if len(block) > 1000: raise SystemExit("index.html 检测到内联业务脚本,请保持 app.js 外链") if "./assets/app.js" not in html: raise SystemExit("index.html 缺少 ./assets/app.js 外链") app_js = out / "assets" / "app.js" if app_js.stat().st_size > 400_000: raise SystemExit( f"app.js 过大({app_js.stat().st_size} bytes),可能再次触发 iOS WebKit overflow" ) print(">>> 已生成外链版 index.html(app.js / app.css 独立文件)") PY echo ">>> 已复制到 $OUT"