Only compress web assets in the CLI (#2329)
* only compress web assets in the CLI * precompressed -> pre-compressed * only enable pre-compression in release builds
This commit is contained in:
1 parent
b147f5a737
commit
a27d4e71ed
13 files changed
+461
-468
No files matched your search
+21
-76
@@ -1,5 +1,8 @@
|
||||
use crate::{
|
||||
assets::{asset_manifest, create_assets_head, process_assets, AssetConfigDropGuard},
|
||||
assets::{
|
||||
asset_manifest, copy_assets_dir, create_assets_head, pre_compress_folder, process_assets,
|
||||
AssetConfigDropGuard,
|
||||
},
|
||||
error::{Error, Result},
|
||||
tools::Tool,
|
||||
};
|
||||
@@ -85,13 +88,12 @@ pub fn build_web(
|
||||
..
|
||||
} = config;
|
||||
let out_dir = config.out_dir();
|
||||
let asset_dir = config.asset_dir();
|
||||
|
||||
let _guard = AssetConfigDropGuard::new();
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
|
||||
// start to build the assets
|
||||
let ignore_files = build_assets(config)?;
|
||||
build_assets(config)?;
|
||||
|
||||
let t_start = std::time::Instant::now();
|
||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||
@@ -156,16 +158,16 @@ pub fn build_web(
|
||||
ExecutableType::Example(name) => cmd.arg("--example").arg(name),
|
||||
};
|
||||
|
||||
let warning_messages = prettier_build(cmd)?;
|
||||
let CargoBuildResult {
|
||||
warnings,
|
||||
output_location,
|
||||
} = prettier_build(cmd)?;
|
||||
let output_location = output_location.context("No output location found")?;
|
||||
|
||||
// [2] Establish the output directory structure
|
||||
let bindgen_outdir = out_dir.join("assets").join("dioxus");
|
||||
|
||||
let input_path = warning_messages
|
||||
.output_location
|
||||
.as_ref()
|
||||
.context("No output location found")?
|
||||
.with_extension("wasm");
|
||||
let input_path = output_location.with_extension("wasm");
|
||||
|
||||
tracing::info!("Running wasm-bindgen");
|
||||
let run_wasm_bindgen = || {
|
||||
@@ -234,6 +236,11 @@ pub fn build_web(
|
||||
tracing::info!("Skipping optimization with wasm-opt, binaryen tool not found.");
|
||||
}
|
||||
|
||||
// If pre-compressing is enabled, we can pre_compress the wasm-bindgen output
|
||||
if config.should_pre_compress_web_assets() {
|
||||
pre_compress_folder(&bindgen_outdir)?;
|
||||
}
|
||||
|
||||
// [5][OPTIONAL] If tailwind is enabled and installed we run it to generate the CSS
|
||||
if dioxus_tools.contains_key("tailwindcss") {
|
||||
let info = dioxus_tools.get("tailwindcss").unwrap();
|
||||
@@ -274,38 +281,7 @@ pub fn build_web(
|
||||
}
|
||||
|
||||
// this code will copy all public file to the output dir
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
skip_exist: false,
|
||||
buffer_size: 64000,
|
||||
copy_inside: false,
|
||||
content_only: false,
|
||||
depth: 0,
|
||||
};
|
||||
|
||||
tracing::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();
|
||||
if path.is_file() {
|
||||
std::fs::copy(&path, out_dir.join(path.file_name().unwrap()))?;
|
||||
} else {
|
||||
match fs_extra::dir::copy(&path, &out_dir, ©_options) {
|
||||
Ok(_) => {}
|
||||
Err(_e) => {
|
||||
tracing::warn!("Error copying dir: {}", _e);
|
||||
}
|
||||
}
|
||||
for ignore in &ignore_files {
|
||||
let ignore = ignore.strip_prefix(&config.asset_dir()).unwrap();
|
||||
let ignore = out_dir.join(ignore);
|
||||
if ignore.is_file() {
|
||||
std::fs::remove_file(ignore)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
copy_assets_dir(config, dioxus_cli_config::Platform::Web)?;
|
||||
|
||||
let assets = if !skip_assets {
|
||||
tracing::info!("Processing assets");
|
||||
@@ -317,8 +293,8 @@ pub fn build_web(
|
||||
};
|
||||
|
||||
Ok(BuildResult {
|
||||
warnings: warning_messages.warnings,
|
||||
executable: warning_messages.output_location,
|
||||
warnings,
|
||||
executable: Some(output_location),
|
||||
elapsed_time: t_start.elapsed().as_millis(),
|
||||
assets,
|
||||
})
|
||||
@@ -366,7 +342,7 @@ pub fn build_desktop(
|
||||
tracing::info!("🚅 Running build [Desktop] command...");
|
||||
|
||||
let t_start = std::time::Instant::now();
|
||||
let ignore_files = build_assets(config)?;
|
||||
build_assets(config)?;
|
||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
let _guard = AssetConfigDropGuard::new();
|
||||
@@ -427,38 +403,7 @@ pub fn build_desktop(
|
||||
copy(res_path, &output_path)?;
|
||||
}
|
||||
|
||||
// this code will copy all public file to the output dir
|
||||
if config.asset_dir().is_dir() {
|
||||
let copy_options = fs_extra::dir::CopyOptions {
|
||||
overwrite: true,
|
||||
skip_exist: false,
|
||||
buffer_size: 64000,
|
||||
copy_inside: false,
|
||||
content_only: false,
|
||||
depth: 0,
|
||||
};
|
||||
|
||||
for entry in std::fs::read_dir(config.asset_dir())?.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
std::fs::copy(&path, &config.out_dir().join(path.file_name().unwrap()))?;
|
||||
} else {
|
||||
match fs_extra::dir::copy(&path, &config.out_dir(), ©_options) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
tracing::warn!("Error copying dir: {}", e);
|
||||
}
|
||||
}
|
||||
for ignore in &ignore_files {
|
||||
let ignore = ignore.strip_prefix(&config.asset_dir()).unwrap();
|
||||
let ignore = config.out_dir().join(ignore);
|
||||
if ignore.is_file() {
|
||||
std::fs::remove_file(ignore)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
copy_assets_dir(config, dioxus_cli_config::Platform::Desktop)?;
|
||||
|
||||
let assets = if !skip_assets {
|
||||
tracing::info!("Processing assets");
|
||||
|
||||
Reference in new issue
Block a user