mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
feat: re-build ssr js on rs change
This commit is contained in:
@@ -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,2 +1,2 @@
|
||||
mod bundle;
|
||||
pub use bundle::bundle;
|
||||
pub use bundle::bundle_axum_source;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use axum_bundler::bundle;
|
||||
use axum_bundler::bundle_axum_source;
|
||||
|
||||
pub fn run() {
|
||||
bundle();
|
||||
bundle_axum_source();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user