Skip to content

Commit ca2c48c

Browse files
committed
feat: implement data-target-path for tailwind
1 parent 1512a80 commit ca2c48c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

site/content/assets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ This will typically look like: `<link data-trunk rel="{type}" href="{path}" ..ot
6464

6565
- `data-inline`: (optional) this attribute will inline the compiled CSS from the tailwind compilation into a `<style>` tag instead of using a `<link rel="stylesheet">` tag.
6666
- `data-integrity`: (optional) the `integrity` digest type for code & script resources. Defaults to plain `sha384`.
67+
- `data-target-path`: (optional) Path where the directory is placed inside the dist dir. If not present, the directory is placed in the dist root. The path must be a relative path without `..`.
6768

6869
## icon
6970

src/pipelines/tailwind_css.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! Tailwind CSS asset pipeline.
22
3-
use super::{AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_HREF, ATTR_INLINE};
3+
use super::{
4+
data_target_path, AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_HREF,
5+
ATTR_INLINE,
6+
};
47
use crate::common;
8+
use crate::common::{dist_relative, target_path};
59
use crate::config::RtcBuild;
610
use crate::processing::integrity::{IntegrityType, OutputDigest};
711
use crate::tools::{self, Application};
@@ -26,6 +30,8 @@ pub struct TailwindCss {
2630
attrs: Attrs,
2731
/// The required integrity setting
2832
integrity: IntegrityType,
33+
/// Optional target path inside the dist dir.
34+
target_path: Option<PathBuf>,
2935
}
3036

3137
impl TailwindCss {
@@ -47,6 +53,7 @@ impl TailwindCss {
4753
let use_inline = attrs.get(ATTR_INLINE).is_some();
4854

4955
let integrity = IntegrityType::from_attrs(&attrs, &cfg)?;
56+
let target_path = data_target_path(&attrs)?;
5057

5158
Ok(Self {
5259
id,
@@ -55,6 +62,7 @@ impl TailwindCss {
5562
use_inline,
5663
integrity,
5764
attrs,
65+
target_path,
5866
})
5967
}
6068

@@ -108,7 +116,11 @@ impl TailwindCss {
108116
.filehash
109117
.then(|| format!("{}-{:x}.css", &self.asset.file_stem.to_string_lossy(), hash))
110118
.unwrap_or(file_name);
111-
let file_path = self.cfg.staging_dist.join(&file_name);
119+
120+
let result_dir =
121+
target_path(&self.cfg.staging_dist, self.target_path.as_deref(), None).await?;
122+
let file_path = result_dir.join(&file_name);
123+
let file_href = dist_relative(&self.cfg.staging_dist, &file_path)?;
112124

113125
let integrity = OutputDigest::generate_from(self.integrity, css.as_bytes());
114126

@@ -118,7 +130,7 @@ impl TailwindCss {
118130
.context("error writing tailwind css pipeline output")?;
119131

120132
// Generate a hashed reference to the new CSS file.
121-
CssRef::File(file_name, integrity)
133+
CssRef::File(file_href, integrity)
122134
};
123135

124136
tracing::debug!(path = ?rel_path, "finished compiling tailwind css");

0 commit comments

Comments
 (0)