Merge pull request #1807 from ealmloff/assets-optional

Only support manganis in the CLI
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-01-11 12:18:24 -08:00
commit 3ef15577eb
20 files changed
+131 -222

No files matched your search

+2 -5
View File
@@ -12,17 +12,14 @@ pub fn asset_manifest(crate_config: &CrateConfig) -> AssetManifest {
}
/// Create a head file that contains all of the imports for assets that the user project uses
pub fn create_assets_head(config: &CrateConfig) -> Result<()> {
let manifest = asset_manifest(config);
pub fn create_assets_head(config: &CrateConfig, manifest: &AssetManifest) -> Result<()> {
let mut file = File::create(config.out_dir.join("__assets_head.html"))?;
file.write_all(manifest.head().as_bytes())?;
Ok(())
}
/// Process any assets collected from the binary
pub(crate) fn process_assets(config: &CrateConfig) -> anyhow::Result<()> {
let manifest = asset_manifest(config);
pub(crate) fn process_assets(config: &CrateConfig, manifest: &AssetManifest) -> anyhow::Result<()> {
let static_asset_output_dir = PathBuf::from(
config
.dioxus_config
+25 -13
View File
@@ -9,7 +9,7 @@ use dioxus_cli_config::CrateConfig;
use dioxus_cli_config::ExecutableType;
use indicatif::{ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use serde::Serialize;
use manganis_cli_support::{AssetManifest, ManganisSupportGuard};
use std::{
fs::{copy, create_dir_all, File},
io::Read,
@@ -23,10 +23,11 @@ lazy_static! {
static ref PROGRESS_BARS: indicatif::MultiProgress = indicatif::MultiProgress::new();
}
#[derive(Serialize, Debug, Clone)]
#[derive(Debug, Clone)]
pub struct BuildResult {
pub warnings: Vec<Diagnostic>,
pub elapsed_time: u128,
pub assets: Option<AssetManifest>,
}
pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildResult> {
@@ -47,7 +48,8 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildRe
..
} = config;
let _gaurd = WebAssetConfigDropGuard::new();
let _guard = WebAssetConfigDropGuard::new();
let _manganis_support = ManganisSupportGuard::default();
// start to build the assets
let ignore_files = build_assets(config)?;
@@ -261,13 +263,18 @@ pub fn build(config: &CrateConfig, _: bool, skip_assets: bool) -> Result<BuildRe
}
}
if !skip_assets {
process_assets(config)?;
}
let assets = if !skip_assets {
let assets = asset_manifest(config);
process_assets(config, &assets)?;
Some(assets)
} else {
None
};
Ok(BuildResult {
warnings: warning_messages,
elapsed_time: t_start.elapsed().as_millis(),
assets,
})
}
@@ -281,6 +288,7 @@ pub fn build_desktop(
let t_start = std::time::Instant::now();
let ignore_files = build_assets(config)?;
let _guard = dioxus_cli_config::__private::save_config(config);
let _manganis_support = ManganisSupportGuard::default();
let mut cmd = subprocess::Exec::cmd("cargo")
.env("CARGO_TARGET_DIR", &config.target_dir)
@@ -394,12 +402,16 @@ pub fn build_desktop(
}
}
if !skip_assets {
let assets = if !skip_assets {
let assets = asset_manifest(config);
// Collect assets
process_assets(config)?;
process_assets(config, &assets)?;
// Create the __assets_head.html file for bundling
create_assets_head(config)?;
}
create_assets_head(config, &assets)?;
Some(assets)
} else {
None
};
log::info!(
"🚩 Build completed: [./{}]",
@@ -411,6 +423,7 @@ pub fn build_desktop(
Ok(BuildResult {
warnings: warning_messages,
elapsed_time: t_start.elapsed().as_millis(),
assets,
})
}
@@ -470,7 +483,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
Ok(warning_messages)
}
pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String {
pub fn gen_page(config: &CrateConfig, manifest: Option<&AssetManifest>, serve: bool) -> String {
let _gaurd = WebAssetConfigDropGuard::new();
let crate_root = crate_root().unwrap();
@@ -515,8 +528,7 @@ pub fn gen_page(config: &CrateConfig, serve: bool, skip_assets: bool) -> String
{
style_str.push_str("<link rel=\"stylesheet\" href=\"/{base_path}/tailwind.css\">\n");
}
if !skip_assets {
let manifest = asset_manifest(config);
if let Some(manifest) = manifest {
style_str.push_str(&manifest.head());
}
+6 -8
View File
@@ -52,12 +52,10 @@ impl Build {
// #[cfg(feature = "plugin")]
// let _ = PluginManager::on_build_start(&crate_config, &platform);
match platform {
Platform::Web => {
crate::builder::build(&crate_config, false, self.build.skip_assets)?;
}
let build_result = match platform {
Platform::Web => crate::builder::build(&crate_config, false, self.build.skip_assets)?,
Platform::Desktop => {
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?;
crate::builder::build_desktop(&crate_config, false, self.build.skip_assets)?
}
Platform::Fullstack => {
// Fullstack mode must be built with web configs on the desktop (server) binary as well as the web binary
@@ -87,12 +85,12 @@ impl Build {
};
let _gaurd =
FullstackServerEnvGuard::new(self.build.force_debug, self.build.release);
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?;
crate::builder::build_desktop(&desktop_config, false, self.build.skip_assets)?
}
}
}
};
let temp = gen_page(&crate_config, false, self.build.skip_assets);
let temp = gen_page(&crate_config, build_result.assets.as_ref(), false);
let mut file = std::fs::File::create(
crate_config
+6 -5
View File
@@ -1,4 +1,5 @@
use dioxus_cli_config::Platform;
use manganis_cli_support::AssetManifest;
use super::*;
use std::{fs::create_dir_all, io::Write, path::PathBuf};
@@ -47,9 +48,6 @@ impl Serve {
match platform {
Platform::Web => {
// generate dev-index page
Serve::regen_dev_page(&crate_config, self.serve.skip_assets)?;
// start the develop server
server::web::startup(
self.serve.port,
@@ -69,8 +67,11 @@ impl Serve {
Ok(())
}
pub fn regen_dev_page(crate_config: &CrateConfig, skip_assets: bool) -> Result<()> {
let serve_html = gen_page(crate_config, true, skip_assets);
pub fn regen_dev_page(
crate_config: &CrateConfig,
manifest: Option<&AssetManifest>,
) -> anyhow::Result<()> {
let serve_html = gen_page(crate_config, manifest, true);
let dist_path = crate_config
.crate_dir
+1 -1
View File
@@ -49,7 +49,7 @@ async fn main() -> anyhow::Result<()> {
let _dioxus_config = DioxusConfig::load(Some(bin.clone()))
.map_err(|e| anyhow!("Failed to load Dioxus config because: {e}"))?
.unwrap_or_else(|| {
log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
log::info!("You appear to be creating a Dioxus project from scratch; we will use the default config");
DioxusConfig::default()
});
+4 -1
View File
@@ -111,6 +111,9 @@ pub async fn serve(
) -> Result<()> {
let first_build_result = crate::builder::build(&config, false, skip_assets)?;
// generate dev-index page
Serve::regen_dev_page(&config, first_build_result.assets.as_ref())?;
log::info!("🚀 Starting development server...");
// WS Reload Watching
@@ -448,7 +451,7 @@ fn build(config: &CrateConfig, reload_tx: &Sender<()>, skip_assets: bool) -> Res
// change the websocket reload state to true;
// the page will auto-reload.
if config.dioxus_config.web.watcher.reload_html {
let _ = Serve::regen_dev_page(config, skip_assets);
let _ = Serve::regen_dev_page(config, result.assets.as_ref());
}
let _ = reload_tx.send(());
Ok(result)