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#""#,
- attrs = AttrWriter::new(&attrs, &[]),
+ attrs = AttrWriter::new(&attrs, AttrWriter::EXCLUDE_SCRIPT),
base = &self.cfg.public_url,
file = self.file
));
diff --git a/src/pipelines/mod.rs b/src/pipelines/mod.rs
index 533e9228..67d06b6d 100644
--- a/src/pipelines/mod.rs
+++ b/src/pipelines/mod.rs
@@ -45,6 +45,7 @@ const ATTR_HREF: &str = "href";
const ATTR_SRC: &str = "src";
const ATTR_TYPE: &str = "type";
const ATTR_REL: &str = "rel";
+const ATTR_MINIFY: &str = "data-no-minify";
const SNIPPETS_DIR: &str = "snippets";
const TRUNK_ID: &str = "data-trunk-id";
const PNG_OPTIMIZATION_LEVEL: u8 = 6;
@@ -352,11 +353,21 @@ impl<'a> AttrWriter<'a> {
ATTR_INLINE,
ATTR_SRC,
ATTR_TYPE,
+ ATTR_MINIFY,
];
/// Whereas on link elements, the MIME type for css is A-OK. You can even specify a custom
/// MIME type.
- pub(self) const EXCLUDE_CSS_LINK: &'static [&'static str] =
- &[TRUNK_ID, ATTR_HREF, ATTR_REL, ATTR_INLINE, ATTR_SRC];
+ pub(self) const EXCLUDE_CSS_LINK: &'static [&'static str] = &[
+ TRUNK_ID,
+ ATTR_HREF,
+ ATTR_REL,
+ ATTR_INLINE,
+ ATTR_SRC,
+ ATTR_MINIFY,
+ ];
+
+ /// Attributes to ignore for