build(gui): build.rs auto-runs npm run build, no more stale frontend bundle
Reproduction:
cargo build --release -p jarvis-gui # before this commit
→ Tauri'\''s generate_context!() reads frontend/dist/client which is
whatever the user (or me) last built, possibly hours ago. Result:
new release exe ships with stale UI. Caught when /commands page
kept rendering the placeholder after the new code was committed
and the binary was rebuilt — because dist/ was generated before
the Svelte file was rewritten.
Fix: build.rs now invokes `npm run build` in frontend/ on every
relink, and emits cargo:rerun-if-changed for frontend/src and
package.json so cargo also reruns build.rs when Svelte/TS sources
change. `cargo tauri build` still works (it runs npm twice, which
is wasteful but harmless). If npm is not installed (unlikely but
possible on a Rust-only CI), prints a cargo warning and bundles
whatever dist is on disk.
`dist` stays in frontend/.gitignore — this just makes sure a local
working copy always has a fresh dist before Tauri picks it up.
This commit is contained in:
parent
a7c002c9d4
commit
a3bdf90237
1 changed files with 33 additions and 2 deletions
|
|
@ -1,9 +1,40 @@
|
|||
fn main() {
|
||||
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let lib_path = std::path::Path::new(&manifest_dir)
|
||||
.join("..\\..\\lib\\windows\\amd64");
|
||||
let manifest_path = std::path::Path::new(&manifest_dir);
|
||||
|
||||
let lib_path = manifest_path.join("..\\..\\lib\\windows\\amd64");
|
||||
println!("cargo:rustc-link-search=native={}", lib_path.display());
|
||||
|
||||
// Vite outputs the Svelte bundle into ../../frontend/dist/client. If the
|
||||
// user runs a bare `cargo build -p jarvis-gui` without going through
|
||||
// `cargo tauri build`, the beforeBuildCommand in tauri.conf.json never
|
||||
// fires and the new release exe ends up bundling whatever stale dist is
|
||||
// sitting on disk — including UI states from days ago. Force a rebuild
|
||||
// here when any Svelte / TS source under frontend/src changes.
|
||||
let frontend = manifest_path.join("..\\..\\frontend");
|
||||
let src = frontend.join("src");
|
||||
if src.is_dir() {
|
||||
println!("cargo:rerun-if-changed={}", src.display());
|
||||
println!("cargo:rerun-if-changed={}", frontend.join("package.json").display());
|
||||
|
||||
let npm = if cfg!(target_os = "windows") { "npm.cmd" } else { "npm" };
|
||||
let status = std::process::Command::new(npm)
|
||||
.arg("run")
|
||||
.arg("build")
|
||||
.current_dir(&frontend)
|
||||
.status();
|
||||
match status {
|
||||
Ok(s) if s.success() => {
|
||||
println!("cargo:warning=jarvis-gui: frontend rebuilt via npm run build");
|
||||
}
|
||||
Ok(s) => {
|
||||
println!("cargo:warning=jarvis-gui: npm run build exited with {}", s);
|
||||
}
|
||||
Err(e) => {
|
||||
println!("cargo:warning=jarvis-gui: npm not found ({}). Bundling existing dist; run `npm install && npm run build` in frontend/ if the UI looks stale.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tauri_build::build()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue