diff --git a/Cargo.lock b/Cargo.lock index 1f7a0f6e5..bf9bd9902 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5902,7 +5902,7 @@ dependencies = [ [[package]] name = "manganis" version = "0.1.0" -source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad" +source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538" dependencies = [ "manganis-macro", ] @@ -5910,7 +5910,7 @@ dependencies = [ [[package]] name = "manganis-cli-support" version = "0.1.0" -source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad" +source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538" dependencies = [ "anyhow", "cargo-lock 9.0.0", @@ -5936,7 +5936,7 @@ dependencies = [ [[package]] name = "manganis-common" version = "0.1.0" -source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad" +source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538" dependencies = [ "anyhow", "base64 0.21.7", @@ -5951,7 +5951,7 @@ dependencies = [ [[package]] name = "manganis-macro" version = "0.0.1" -source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad" +source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538" dependencies = [ "base64 0.21.7", "manganis-cli-support", diff --git a/Cargo.toml b/Cargo.toml index 9404619a2..86d9133ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,11 +99,11 @@ thiserror = "1.0.40" prettyplease = { package = "prettier-please", version = "0.2", features = [ "verbatim", ] } -manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4", features = [ +manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", rev = "f982698", features = [ "webp", "html", ] } -manganis = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4" } +manganis = { git = "https://github.com/DioxusLabs/collect-assets", rev = "f982698" } # This is a "virtual package" # It is not meant to be published, but is used so "cargo run --example XYZ" works properly diff --git a/examples/custom_assets.rs b/examples/custom_assets.rs index 7f9503a5f..54ed831d5 100644 --- a/examples/custom_assets.rs +++ b/examples/custom_assets.rs @@ -4,7 +4,8 @@ use dioxus::prelude::*; static ASSET_PATH: &str = "examples/assets/logo.png"; #[cfg(feature = "collect-assets")] -static ASSET_PATH: &str = manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif)); +static ASSET_PATH: &str = + manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif)).path(); fn main() { launch(app); diff --git a/examples/tailwind/dist/tailwind3531548035813279582.css b/examples/tailwind/dist/tailwind3531548035813279582.css deleted file mode 100644 index 2196a9412..000000000 --- a/examples/tailwind/dist/tailwind3531548035813279582.css +++ /dev/null @@ -1 +0,0 @@ -*,:before,:after{box-sizing:border-box;border:0 solid #e5e7eb}:before,:after{--tw-content:""}html{-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-feature-settings:normal;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}body{line-height:inherit;margin:0}hr{color:inherit;border-top-width:1px;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button;background-color:#0000;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{margin:0;padding:0;list-style:none}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}[hidden]{display:none}*,:before,:after,::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness:proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:#3b82f680;--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.container{width:100%}@media (width>=640px){.container{max-width:640px}}@media (width>=768px){.container{max-width:768px}}@media (width>=1024px){.container{max-width:1024px}}@media (width>=1280px){.container{max-width:1280px}}@media (width>=1536px){.container{max-width:1536px}}.mx-auto{margin-left:auto;margin-right:auto}.mb-16{margin-bottom:4rem}.mb-4{margin-bottom:1rem}.mb-8{margin-bottom:2rem}.ml-1{margin-left:.25rem}.ml-3{margin-left:.75rem}.ml-4{margin-left:1rem}.mr-5{margin-right:1.25rem}.mt-4{margin-top:1rem}.flex{display:flex}.inline-flex{display:inline-flex}.hidden{display:none}.h-10{height:2.5rem}.h-4{height:1rem}.w-10{width:2.5rem}.w-4{width:1rem}.w-5\/6{width:83.3333%}.flex-col{flex-direction:column}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.justify-center{justify-content:center}.rounded{border-radius:.25rem}.rounded-full{border-radius:9999px}.border-0{border-width:0}.bg-gray-800{--tw-bg-opacity:1;background-color:rgb(31 41 55/var(--tw-bg-opacity))}.bg-gray-900{--tw-bg-opacity:1;background-color:rgb(17 24 39/var(--tw-bg-opacity))}.bg-indigo-500{--tw-bg-opacity:1;background-color:rgb(99 102 241/var(--tw-bg-opacity))}.object-cover{-o-object-fit:cover;object-fit:cover}.object-center{-o-object-position:center;object-position:center}.p-2{padding:.5rem}.p-5{padding:1.25rem}.px-3{padding-left:.75rem;padding-right:.75rem}.px-5{padding-left:1.25rem;padding-right:1.25rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.py-1{padding-top:.25rem;padding-bottom:.25rem}.py-2{padding-top:.5rem;padding-bottom:.5rem}.py-24{padding-top:6rem;padding-bottom:6rem}.text-center{text-align:center}.text-3xl{font-size:1.875rem;line-height:2.25rem}.text-base{font-size:1rem;line-height:1.5rem}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.font-medium{font-weight:500}.leading-relaxed{line-height:1.625}.text-gray-400{--tw-text-opacity:1;color:rgb(156 163 175/var(--tw-text-opacity))}.text-white{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.hover\:bg-gray-700:hover{--tw-bg-opacity:1;background-color:rgb(55 65 81/var(--tw-bg-opacity))}.hover\:bg-indigo-600:hover{--tw-bg-opacity:1;background-color:rgb(79 70 229/var(--tw-bg-opacity))}.hover\:text-white:hover{--tw-text-opacity:1;color:rgb(255 255 255/var(--tw-text-opacity))}.focus\:outline-none:focus{outline-offset:2px;outline:2px solid #0000}@media (width>=640px){.sm\:text-4xl{font-size:2.25rem;line-height:2.5rem}}@media (width>=768px){.md\:mb-0{margin-bottom:0}.md\:ml-auto{margin-left:auto}.md\:mt-0{margin-top:0}.md\:w-1\/2{width:50%}.md\:flex-row{flex-direction:row}.md\:items-start{align-items:flex-start}.md\:pr-16{padding-right:4rem}.md\:text-left{text-align:left}}@media (width>=1024px){.lg\:inline-block{display:inline-block}.lg\:w-full{width:100%}.lg\:max-w-lg{max-width:32rem}.lg\:flex-grow{flex-grow:1}.lg\:pr-24{padding-right:6rem}} \ No newline at end of file diff --git a/examples/tailwind/src/main.rs b/examples/tailwind/src/main.rs index ab21af5e4..05c7a1021 100644 --- a/examples/tailwind/src/main.rs +++ b/examples/tailwind/src/main.rs @@ -2,7 +2,7 @@ use dioxus::prelude::*; -const _STYLE: &str = manganis::mg!(file("./public/tailwind.css")); +const _STYLE: &str = manganis::mg!(file("public/tailwind.css")); fn main() { launch(app); diff --git a/packages/cli/src/assets.rs b/packages/cli/src/assets.rs index c9fee435f..897ba6320 100644 --- a/packages/cli/src/assets.rs +++ b/packages/cli/src/assets.rs @@ -37,9 +37,9 @@ pub(crate) fn process_assets(config: &CrateConfig, manifest: &AssetManifest) -> } /// A guard that sets up the environment for the web renderer to compile in. This guard sets the location that assets will be served from -pub(crate) struct WebAssetConfigDropGuard; +pub(crate) struct AssetConfigDropGuard; -impl WebAssetConfigDropGuard { +impl AssetConfigDropGuard { pub fn new() -> Self { // Set up the collect asset config manganis_cli_support::Config::default() @@ -49,7 +49,7 @@ impl WebAssetConfigDropGuard { } } -impl Drop for WebAssetConfigDropGuard { +impl Drop for AssetConfigDropGuard { fn drop(&mut self) { // Reset the config manganis_cli_support::Config::default().save(); diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs index 17333ad17..d33778ec9 100644 --- a/packages/cli/src/builder.rs +++ b/packages/cli/src/builder.rs @@ -1,5 +1,5 @@ use crate::{ - assets::{asset_manifest, create_assets_head, process_assets, WebAssetConfigDropGuard}, + assets::{asset_manifest, create_assets_head, process_assets, AssetConfigDropGuard}, error::{Error, Result}, tools::Tool, }; @@ -87,7 +87,7 @@ pub fn build( let out_dir = config.out_dir(); let asset_dir = config.asset_dir(); - let _guard = WebAssetConfigDropGuard::new(); + let _guard = AssetConfigDropGuard::new(); let _manganis_support = ManganisSupportGuard::default(); // start to build the assets @@ -339,6 +339,7 @@ pub fn build_desktop( let ignore_files = build_assets(config)?; let _guard = dioxus_cli_config::__private::save_config(config); let _manganis_support = ManganisSupportGuard::default(); + let _guard = AssetConfigDropGuard::new(); let mut cmd = subprocess::Exec::cmd("cargo") .set_rust_flags(rust_flags) @@ -535,7 +536,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result> { } pub fn gen_page(config: &CrateConfig, manifest: Option<&AssetManifest>, serve: bool) -> String { - let _gaurd = WebAssetConfigDropGuard::new(); + let _guard = AssetConfigDropGuard::new(); let crate_root = crate_root().unwrap(); let custom_html_file = crate_root.join("index.html"); diff --git a/packages/cli/src/cli/build.rs b/packages/cli/src/cli/build.rs index c30cb29e8..8c47fcda7 100644 --- a/packages/cli/src/cli/build.rs +++ b/packages/cli/src/cli/build.rs @@ -1,6 +1,7 @@ +use crate::assets::AssetConfigDropGuard; #[cfg(feature = "plugin")] use crate::plugin::PluginManager; -use crate::{assets::WebAssetConfigDropGuard, server::fullstack}; +use crate::server::fullstack; use dioxus_cli_config::Platform; use super::*; @@ -69,7 +70,7 @@ impl Build { Platform::Fullstack => { // Fullstack mode must be built with web configs on the desktop // (server) binary as well as the web binary - let _config = WebAssetConfigDropGuard::new(); + let _config = AssetConfigDropGuard::new(); let client_rust_flags = fullstack::client_rust_flags(&self.build); let server_rust_flags = fullstack::server_rust_flags(&self.build); { diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index 23ccd35ff..1337f0325 100644 --- a/packages/desktop/src/protocol.rs +++ b/packages/desktop/src/protocol.rs @@ -105,7 +105,16 @@ pub(super) fn index_request( // Insert a custom head if provided // We look just for the closing head tag. If a user provided a custom index with weird syntax, this might fail - if let Some(head) = custom_head { + let head = match custom_head { + Some(mut head) => { + if let Some(assets_head) = assets_head() { + head.push_str(&assets_head); + } + Some(head) + } + None => assets_head(), + }; + if let Some(head) = head { index.insert_str(index.find("").expect("Head element to exist"), &head); } @@ -124,46 +133,40 @@ pub(super) fn index_request( .ok() } -// let assets_head = { -// #[cfg(all( -// debug_assertions, -// any( -// target_os = "windows", -// target_os = "macos", -// target_os = "linux", -// target_os = "dragonfly", -// target_os = "freebsd", -// target_os = "netbsd", -// target_os = "openbsd" -// ) -// ))] -// { -// None -// } -// #[cfg(not(all( -// debug_assertions, -// any( -// target_os = "windows", -// target_os = "macos", -// target_os = "linux", -// target_os = "dragonfly", -// target_os = "freebsd", -// target_os = "netbsd", -// target_os = "openbsd" -// ) -// )))] -// { -// let head = crate::protocol::get_asset_root_or_default(); -// let head = head.join("dist/__assets_head.html"); -// match std::fs::read_to_string(&head) { -// Ok(s) => Some(s), -// Err(err) => { -// tracing::error!("Failed to read {head:?}: {err}"); -// None -// } -// } -// } -// }; +fn assets_head() -> Option { + #[cfg(any( + target_os = "windows", + target_os = "macos", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] + { + let head = crate::protocol::get_asset_root_or_default(); + let head = head.join("__assets_head.html"); + match std::fs::read_to_string(&head) { + Ok(s) => Some(s), + Err(err) => { + tracing::error!("Failed to read {head:?}: {err}"); + None + } + } + } + #[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )))] + { + None + } +} /// Handle a request from the webview ///