Skip to content

Commit

Permalink
Allow tailwind config path to be specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
azriel91 authored and ctron committed Dec 16, 2024
1 parent 607772b commit 7b4198b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pipelines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use std::{
use tokio::{fs, sync::mpsc, task::JoinHandle};

const ATTR_INLINE: &str = "data-inline";
const ATTR_CONFIG: &str = "data-config";
const ATTR_HREF: &str = "href";
const ATTR_SRC: &str = "src";
const ATTR_TYPE: &str = "type";
Expand Down
13 changes: 11 additions & 2 deletions src/pipelines/tailwind_css.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Tailwind CSS asset pipeline.
use super::{
data_target_path, AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_HREF,
ATTR_INLINE, ATTR_NO_MINIFY,
data_target_path, AssetFile, AttrWriter, Attrs, TrunkAssetPipelineOutput, ATTR_CONFIG,
ATTR_HREF, ATTR_INLINE, ATTR_NO_MINIFY,
};
use crate::{
common::{self, dist_relative, html_rewrite::Document, nonce, target_path},
Expand Down Expand Up @@ -32,6 +32,8 @@ pub struct TailwindCss {
no_minify: bool,
/// Optional target path inside the dist dir.
target_path: Option<PathBuf>,
/// Optional tailwind config to use.
tailwind_config: Option<String>,
}

impl TailwindCss {
Expand All @@ -47,6 +49,7 @@ impl TailwindCss {
let href_attr = attrs.get(ATTR_HREF).context(
r#"required attr `href` missing for <link data-trunk rel="tailwind-css" .../> element"#,
)?;
let tailwind_config = attrs.get(ATTR_CONFIG).cloned();
let mut path = PathBuf::new();
path.extend(href_attr.split('/'));
let asset = AssetFile::new(&html_dir, path).await?;
Expand All @@ -65,6 +68,7 @@ impl TailwindCss {
attrs,
no_minify,
target_path,
tailwind_config,
})
}

Expand Down Expand Up @@ -95,6 +99,11 @@ impl TailwindCss {

let mut args = vec!["--input", &path_str, "--output", &file_path];

if let Some(tailwind_config) = self.tailwind_config.as_ref() {
args.push("--config");
args.push(tailwind_config);
}

if self.cfg.minify_asset(self.no_minify) {
args.push("--minify");
}
Expand Down

0 comments on commit 7b4198b

Please sign in to comment.