Hashless assets (#4312)

* add support for external assets

* fix playwright tests

* add more documentation to with_hash_suffix

* restore external asset hashing tests

* Update gtk workflow dependencies

* fix doc test

* multiple versions of libgtk

* clear dx in playwright tests

* fix fullstack caching test

* try without apt cache

* cache everything except libxdo-dev

* revert ci changes

* fix wasm asset options

* fix merge conflict

* recommend the used attribute instead

* Move options to AssetOptionsBuilder

* Don't deprecate non-canonical new asset options functions

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2025-06-30 19:21:49 -07:00
1 parent 0bd376b873
commit e74c838441
22 files changed
+569 -316

No files matched your search

@@ -35,7 +35,7 @@ impl Parse for AssetParser {
// ```
// asset!(
// "/assets/myfile.png",
// ImageAssetOptions::new()
// AssetOptions::image()
// .format(ImageFormat::Jpg)
// .size(512, 512)
// )
@@ -84,8 +84,9 @@ impl ToTokens for AssetParser {
asset_string.hash(&mut hash);
let asset_hash = format!("{:016x}", hash.finish());
// Generate the link section for the asset
// The link section includes the source path and the output path of the asset
// Generate the link section for the asset. The link section includes the source path and the
// output path of the asset. We force the asset to be included in the binary even if it is unused
// if the asset is unhashed
let link_section = crate::generate_link_section(quote!(__ASSET), &asset_hash);
// generate the asset::new method to deprecate the `./assets/blah.css` syntax
@@ -96,7 +97,7 @@ impl ToTokens for AssetParser {
};
let options = if self.options.is_empty() {
quote! { manganis::AssetOptions::Unknown }
quote! { manganis::AssetOptions::builder() }
} else {
self.options.clone()
};
@@ -34,7 +34,7 @@ impl Parse for CssModuleParser {
// Optional options
let mut options = input.parse::<TokenStream>()?;
if options.is_empty() {
options = quote! { manganis::CssModuleAssetOptions::new() }
options = quote! { manganis::AssetOptions::css_module() }
}
let asset_parser = AssetParser {
+5 -5
View File
@@ -46,17 +46,17 @@ use linker::generate_link_section;
/// Resize the image at compile time to make the assets file size smaller:
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize};
/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_size(ImageSize::Manual { width: 52, height: 52 }));
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 52, height: 52 }));
/// ```
/// Or convert the image at compile time to a web friendly format:
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_format(ImageFormat::Avif));
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Avif));
/// ```
/// You can mark images as preloaded to make them load faster in your app
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions};
/// const _: Asset = asset!("/assets/image.png", ImageAssetOptions::new().with_preload(true));
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true));
/// ```
#[proc_macro]
pub fn asset(input: TokenStream) -> TokenStream {
@@ -78,7 +78,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// - An optional `CssModuleAssetOptions` struct to configure the processing of your CSS module.
///
/// ```rust
/// css_module!(StylesIdent = "/my.module.css", CssModuleAssetOptions::new());
/// css_module!(StylesIdent = "/my.module.css", AssetOptions::css_module());
/// ```
///
/// The styles struct can be made public by appending `pub` before the identifier.
@@ -131,7 +131,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// use manganis::CssModuleAssetOptions;
///
/// css_module!(Styles = "/mycss.module.css",
/// CssModuleAssetOptions::new()
/// AssetOptions::css_module()
/// .with_minify(true)
/// .with_preload(false),
/// );