From aebdcd6d99208c4fb80cf31779bc7f6c9b92b952 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 4 Jun 2026 11:34:13 +0800 Subject: [PATCH] fix(build): fix WASM 404 in production by creating symlinks in wasm/ directory --- Makefile | 3 +++ scripts/fix-wasm-paths.py | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 scripts/fix-wasm-paths.py diff --git a/Makefile b/Makefile index 711ca51..27a3769 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,9 @@ build: @$(MAKE) highlight-css @tailwindcss -i input.css -o public/style.css --minify @dx build --release + @echo "Fixing WASM paths for production..." + @python3 scripts/fix-wasm-paths.py + @echo "WASM paths fixed." highlight-css: @cargo run --bin generate_highlight_css diff --git a/scripts/fix-wasm-paths.py b/scripts/fix-wasm-paths.py new file mode 100755 index 0000000..94e64db --- /dev/null +++ b/scripts/fix-wasm-paths.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +""" +Fix WASM paths for Dioxus production builds. + +Dioxus 0.7 hashes WASM/JS files and places them in assets/, but index.html +still references the old wasm/ paths. This script creates symlinks to bridge +the gap. +""" + +import json +import os +import sys + + +def main(): + manifest_path = "target/dx/yggdrasil/release/web/.manifest.json" + + if not os.path.exists(manifest_path): + print("Manifest not found, skipping WASM path fix") + sys.exit(0) + + with open(manifest_path) as f: + data = json.load(f) + + wasm_dir = "target/dx/yggdrasil/release/web/public/wasm" + assets_dir = "target/dx/yggdrasil/release/web/public/assets" + os.makedirs(wasm_dir, exist_ok=True) + + for path, info_list in data["assets"].items(): + if "wasm/" in path: + for info in info_list: + bundled = info["bundled_path"] + original_name = os.path.basename(path) + src = os.path.join(assets_dir, bundled) + dst = os.path.join(wasm_dir, original_name) + + if os.path.exists(src): + if os.path.islink(dst) or os.path.exists(dst): + os.remove(dst) + os.symlink(os.path.relpath(src, os.path.dirname(dst)), dst) + print(f"Linked: wasm/{original_name} -> assets/{bundled}") + else: + print(f"ERROR: Source not found: {src}") + sys.exit(1) + + +if __name__ == "__main__": + main()