diff options
| -rw-r--r-- | server/Cargo.toml | 1 | ||||
| -rw-r--r-- | ui/Cargo.toml | 1 | ||||
| -rw-r--r-- | ui/client-scripts/Cargo.toml | 4 | ||||
| -rw-r--r-- | ui/client-scripts/src/lib.rs | 34 |
4 files changed, 40 insertions, 0 deletions
diff --git a/server/Cargo.toml b/server/Cargo.toml index 103c919..2871e5a 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -35,3 +35,4 @@ tokio-util = { version = "0.7.17", features = ["io", "io-util"] } [features] reload_css = ["jellyui/reload_css"] +reload_js = ["jellyui/reload_js"] diff --git a/ui/Cargo.toml b/ui/Cargo.toml index 8801901..6183e66 100644 --- a/ui/Cargo.toml +++ b/ui/Cargo.toml @@ -17,3 +17,4 @@ jellyui-locale = { path = "locale" } [features] reload_css = ["jellyui-client-style/reload"] +reload_js = ["jellyui-client-scripts/reload"] diff --git a/ui/client-scripts/Cargo.toml b/ui/client-scripts/Cargo.toml index c6a8d74..329be0d 100644 --- a/ui/client-scripts/Cargo.toml +++ b/ui/client-scripts/Cargo.toml @@ -5,3 +5,7 @@ edition = "2024" [build-dependencies] glob = "0.3.3" + +[features] +# default = ["reload"] +reload = []
\ No newline at end of file diff --git a/ui/client-scripts/src/lib.rs b/ui/client-scripts/src/lib.rs index 408799a..9ac96e4 100644 --- a/ui/client-scripts/src/lib.rs +++ b/ui/client-scripts/src/lib.rs @@ -5,9 +5,43 @@ */ use std::borrow::Cow; +#[cfg(not(feature = "reload"))] pub fn js_bundle() -> Cow<'static, str> { include_str!(concat!(env!("OUT_DIR"), "/bundle.js")).into() } +#[cfg(not(feature = "reload"))] pub fn js_bundle_map() -> Cow<'static, str> { include_str!(concat!(env!("OUT_DIR"), "/bundle.js.map")).into() } + +#[cfg(feature = "reload")] +pub fn js_bundle() -> Cow<'static, str> { + use std::process::{Command, Stdio}; + + let proc = Command::new("esbuild") + .arg("ui/client-scripts/src/main.ts") + .arg("--bundle") + .arg("--target=esnext") + .arg("--sourcemap") + .arg("--format=esm") + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + + let output = proc.wait_with_output().unwrap(); + + Cow::Owned(if output.status.success() { + String::from_utf8(output.stdout).unwrap() + } else { + format!( + "console.error({:?})", + String::from_utf8(output.stderr).unwrap() + ) + }) +} + +#[cfg(feature = "reload")] +pub fn js_bundle_map() -> Cow<'static, str> { + Cow::Borrowed("") +} |