fix hotreloading issues in the CLI

This commit is contained in:
Jonathan Kelley committed 2024-03-12 13:39:42 -07:00
1 parent d180f569cf
commit ad7a350d2e
37 files changed
+818 -805

No files matched your search

+12 -5
View File
@@ -3,10 +3,9 @@ use crate::{
error::{Error, Result},
tools::Tool,
};
use anyhow::Context;
use cargo_metadata::{diagnostic::Diagnostic, Message};
use dioxus_cli_config::crate_root;
use dioxus_cli_config::CrateConfig;
use dioxus_cli_config::ExecutableType;
use dioxus_cli_config::{crate_root, CrateConfig, ExecutableType};
use indicatif::{ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use manganis_cli_support::{AssetManifest, ManganisSupportGuard};
@@ -67,7 +66,6 @@ impl ExecWithRustFlagsSetter for subprocess::Exec {
/// Note: `rust_flags` argument is only used for the fullstack platform.
pub fn build(
config: &CrateConfig,
_: bool,
skip_assets: bool,
rust_flags: Option<String>,
) -> Result<BuildResult> {
@@ -103,6 +101,7 @@ pub fn build(
let wasm_check_command = std::process::Command::new("rustup")
.args(["show"])
.output()?;
let wasm_check_output = String::from_utf8(wasm_check_command.stdout).unwrap();
if !wasm_check_output.contains("wasm32-unknown-unknown") {
log::info!("wasm32-unknown-unknown target not detected, installing..");
@@ -163,9 +162,10 @@ pub fn build(
let input_path = warning_messages
.output_location
.as_ref()
.unwrap()
.context("No output location found")?
.with_extension("wasm");
log::info!("Running wasm-bindgen");
let bindgen_result = panic::catch_unwind(move || {
// [3] Bindgen the final binary for use easy linking
let mut bindgen_builder = Bindgen::new();
@@ -183,11 +183,13 @@ pub fn build(
.generate(&bindgen_outdir)
.unwrap();
});
if bindgen_result.is_err() {
return Err(Error::BuildFailed("Bindgen build failed! \nThis is probably due to the Bindgen version, dioxus-cli using `0.2.81` Bindgen crate.".to_string()));
}
// check binaryen:wasm-opt tool
log::info!("Running optimization with wasm-opt...");
let dioxus_tools = dioxus_config.application.tools.clone();
if dioxus_tools.contains_key("binaryen") {
let info = dioxus_tools.get("binaryen").unwrap();
@@ -221,6 +223,8 @@ pub fn build(
"Binaryen tool not found, you can use `dx tool add binaryen` to install it."
);
}
} else {
log::info!("Skipping optimization with wasm-opt, binaryen tool not found.");
}
// [5][OPTIONAL] If tailwind is enabled and installed we run it to generate the CSS
@@ -271,6 +275,8 @@ pub fn build(
content_only: false,
depth: 0,
};
log::info!("Copying public assets to the output directory...");
if asset_dir.is_dir() {
for entry in std::fs::read_dir(config.asset_dir())?.flatten() {
let path = entry.path();
@@ -294,6 +300,7 @@ pub fn build(
}
}
log::info!("Processing assets");
let assets = if !skip_assets {
let assets = asset_manifest(executable.executable(), config);
process_assets(config, &assets)?;