minify js at runtime in liveview

This commit is contained in:
Evan Almloff committed 2024-02-01 10:10:05 -06:00
1 parent e2e0a934fd
commit 2371c9eed3
4 files changed
+45 -6

No files matched your search

-1
View File
@@ -84,7 +84,6 @@ exitcode = "1.1.2"
[build-dependencies]
# dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] }
# minify-js = "0.5.6"
# These tests need to be run on the main thread, so they cannot use rust's test harness.
[[test]]
+1 -1
View File
@@ -24,6 +24,7 @@ serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.91"
dioxus-html = { workspace = true, features = ["serialize", "eval", "mounted"] }
rustc-hash = { workspace = true }
minify-js = "0.5.6"
dioxus-core = { workspace = true, features = ["serialize"] }
dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] }
dioxus-hot-reload = { workspace = true, optional = true }
@@ -62,7 +63,6 @@ dioxus = { workspace = true }
[build-dependencies]
# dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] }
# minify-js = "0.5.6"
[features]
default = ["hot-reload"]
+7 -1
View File
@@ -31,6 +31,7 @@ pub enum LiveViewError {
fn handle_edits_code() -> String {
use dioxus_interpreter_js::binary_protocol::SLEDGEHAMMER_JS;
use minify_js::{minify, Session, TopLevelMode};
let serialize_file_uploads = r#"if (
target.tagName === "INPUT" &&
@@ -82,7 +83,12 @@ fn handle_edits_code() -> String {
let main_js = include_str!("./main.js");
format!("{interpreter}\n{main_js}")
let js = format!("{interpreter}\n{main_js}");
let session = Session::new();
let mut out = Vec::new();
minify(&session, TopLevelMode::Module, js.as_bytes(), &mut out).unwrap();
String::from_utf8(out).unwrap()
}
/// This script that gets injected into your app connects this page to the websocket endpoint