Fix iOS WebKit crash by shipping external app.js instead of inlined HTML.
Stop embedding the 1.4MB bundle in index.html to avoid std::overflow_error on launch, validate the iOS asset build, and surface load failures in the native shell. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -18,29 +18,33 @@ cp -R dist/* "$OUT/"
|
||||
|
||||
python3 - <<PY
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
out = Path("$OUT")
|
||||
html_path = out / "index.html"
|
||||
js_path = out / "assets" / "app.js"
|
||||
css_path = out / "assets" / "app.css"
|
||||
html = html_path.read_text(encoding="utf-8")
|
||||
js = js_path.read_text(encoding="utf-8")
|
||||
css = css_path.read_text(encoding="utf-8")
|
||||
|
||||
# 单文件内联,避免 wordloop:// 二次请求脚本失败
|
||||
html = html.replace('<link rel="stylesheet" href="wordloop://app/assets/app.css">', f"<style>{css}</style>")
|
||||
html = html.replace(
|
||||
'<script src="wordloop://app/assets/app.js"></script>',
|
||||
"",
|
||||
)
|
||||
# 脚本放在 </body> 前,确保 #app 已存在(head 内联会导致 Vue mount 失败、白屏)
|
||||
html = html.replace(
|
||||
"</body>",
|
||||
f" <script>{js}</script>\\n </body>",
|
||||
)
|
||||
# 保持外链资源,避免把 ~1.4MB JS 内联进 HTML 导致 WebKit std::overflow_error 崩溃
|
||||
html = html.replace("wordloop://app/assets/", "./assets/")
|
||||
|
||||
script = re.search(r'<script src="\./assets/[^"]+"></script>', html)
|
||||
if script:
|
||||
tag = script.group(0)
|
||||
if tag not in html.split("</body>", 1)[-1]:
|
||||
html = html.replace(tag, "", 1)
|
||||
html = html.replace("</body>", f" {tag}\n </body>", 1)
|
||||
|
||||
html_path.write_text(html, encoding="utf-8")
|
||||
print(">>> 已内联 app.js / app.css 到 index.html")
|
||||
|
||||
if len(html) > 20_000:
|
||||
raise SystemExit("index.html 过大,可能仍含内联 JS,会导致 WebKit overflow 崩溃")
|
||||
for block in re.findall(r"<script>(.*?)</script>", 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 外链")
|
||||
|
||||
print(">>> 已生成外链版 index.html(app.js / app.css 独立文件)")
|
||||
PY
|
||||
|
||||
echo ">>> 已复制到 $OUT"
|
||||
|
||||
Reference in New Issue
Block a user