diff --git a/examples/vanilla/index.html b/examples/vanilla/index.html index 5572d200..8f654961 100644 --- a/examples/vanilla/index.html +++ b/examples/vanilla/index.html @@ -7,6 +7,7 @@ + diff --git a/examples/vanilla/src/not_minified.css b/examples/vanilla/src/not_minified.css new file mode 100644 index 00000000..a3122f19 --- /dev/null +++ b/examples/vanilla/src/not_minified.css @@ -0,0 +1,4 @@ +.should_not_be_minified:checked:hover { + --empty-prop: ; + background-color: black; +} diff --git a/site/content/assets.md b/site/content/assets.md index 202105dd..d557336a 100644 --- a/site/content/assets.md +++ b/site/content/assets.md @@ -54,6 +54,7 @@ This will typically look like: ` Result { let rel_path = crate::common::strip_prefix(&self.asset.path); tracing::info!(path = ?rel_path, "copying & hashing css"); + let minify = self.cfg.release && self.minify && !self.cfg.no_minification; let file = self .asset .copy( &self.cfg.staging_dist, self.cfg.filehash, - self.cfg.release && !self.cfg.no_minification, + minify, AssetFileType::Css, ) .await?; diff --git a/src/pipelines/js.rs b/src/pipelines/js.rs index dda2b681..3ae5052e 100644 --- a/src/pipelines/js.rs +++ b/src/pipelines/js.rs @@ -1,6 +1,6 @@ //! JS asset pipeline. -use super::{AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_SRC}; +use super::{AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_MINIFY, ATTR_SRC}; use crate::{ config::RtcBuild, pipelines::AssetFileType, @@ -26,6 +26,8 @@ pub struct Js { integrity: IntegrityType, /// If it's a JavaScript module (vs a classic script) module: bool, + /// Whether to minify or not + minify: bool, } impl Js { @@ -44,14 +46,8 @@ impl Js { let asset = AssetFile::new(&html_dir, path).await?; let integrity = IntegrityType::from_attrs(&attrs, &cfg)?; - let module = attrs.get("type").map(|s| s.as_str()) == Some("module"); - - // Remove src and data-trunk from attributes. - let attrs = attrs - .into_iter() - .filter(|(x, _)| *x != "src" && !x.starts_with("data-trunk")) - .collect(); + let minify = attrs.get(ATTR_MINIFY).is_none(); Ok(Self { id, @@ -60,6 +56,7 @@ impl Js { module, attrs, integrity, + minify, }) } @@ -74,12 +71,13 @@ impl Js { async fn run(self) -> Result { let rel_path = crate::common::strip_prefix(&self.asset.path); tracing::info!(path = ?rel_path, "copying & hashing js"); + let minify = self.cfg.release && self.minify && !self.cfg.no_minification; let file = self .asset .copy( &self.cfg.staging_dist, self.cfg.filehash, - self.cfg.release && !self.cfg.no_minification, + minify, if self.module { AssetFileType::Mjs } else { @@ -130,7 +128,7 @@ impl JsOutput { dom.select(&super::trunk_script_id_selector(self.id)) .replace_with_html(format!( r#"