feat: re-build ssr js on rs change

This commit is contained in:
Valerio Ageno
2024-05-19 20:44:45 +02:00
parent 4ed6c9902f
commit 04216d93bf
5 changed files with 34 additions and 16 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ mod {route};
route_declarations
}
pub fn bundle() {
pub fn bundle_axum_source() {
println!("Axum project bundling");
let base_path = std::env::current_dir().unwrap();
+1 -1
View File
@@ -1,2 +1,2 @@
mod bundle;
pub use bundle::bundle;
pub use bundle::bundle_axum_source;
+26 -7
View File
@@ -1,7 +1,7 @@
use std::sync::Arc;
use watchexec_supervisor::command::{Command, Program};
use axum_bundler::bundle;
use axum_bundler::bundle_axum_source;
use miette::{IntoDiagnostic, Result};
use watchexec::Watchexec;
use watchexec_signals::Signal;
@@ -9,8 +9,9 @@ use watchexec_supervisor::job::start_job;
#[tokio::main]
pub async fn watch() -> Result<()> {
bundle();
let (job, _) = start_job(Arc::new(Command {
bundle_axum_source();
let (run_server, _) = start_job(Arc::new(Command {
program: Program::Exec {
prog: "cargo".into(),
args: vec!["run".to_string()],
@@ -19,16 +20,34 @@ pub async fn watch() -> Result<()> {
options: Default::default(),
}));
job.start().await;
let (build_server_js, _) = start_job(Arc::new(Command {
program: Program::Exec {
prog: "node_modules/.bin/vite".into(),
// TODO: update output directory: Use .tuono
args: vec![
"build".to_string(),
"--ssr".to_string(),
"--logLevel".to_string(),
"silent".to_string(),
],
}
.into(),
options: Default::default(),
}));
build_server_js.start().await;
run_server.start().await;
let wx = Watchexec::new(move |mut action| {
for event in action.events.iter() {
for path in event.paths() {
if path.0.to_string_lossy().ends_with(".rs") {
job.stop();
run_server.stop();
println!("Reloading server...");
bundle();
job.start();
build_server_js.stop();
build_server_js.start();
bundle_axum_source();
run_server.start();
}
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
use axum_bundler::bundle;
use axum_bundler::bundle_axum_source;
pub fn run() {
bundle();
bundle_axum_source();
}
+4 -5
View File
@@ -9,15 +9,14 @@ pub fn run() {
let vite_path = Path::new("node_modules/.bin/vite");
let vite = current_dir.join(vite_path);
let vite_handler = thread::spawn(move || {
println!("Spawing vite process");
let client_handler = thread::spawn(move || {
let _ = Command::new(vite).arg("dev").output();
});
let build_rs_handler = thread::spawn(move || {
let server_handler = thread::spawn(move || {
bundler::watch().unwrap();
});
let _ = vite_handler.join();
let _ = build_rs_handler.join();
let _ = client_handler.join();
let _ = server_handler.join();
}