cargo_leptos/config/
tailwind.rs1use camino::Utf8PathBuf;
2
3use super::{ProjectConfig, VersionConfig};
4use crate::internal_prelude::*;
5
6#[derive(Clone, Debug)]
7pub struct TailwindConfig {
8 pub input_file: Utf8PathBuf,
9 pub config_file: Option<Utf8PathBuf>,
10 pub tmp_file: Utf8PathBuf,
11}
12
13impl TailwindConfig {
14 pub fn new(conf: &ProjectConfig) -> Result<Option<Self>> {
15 let input_file = if let Some(input_file) = conf.tailwind_input_file.clone() {
16 conf.config_dir.join(input_file)
17 } else {
18 if conf.tailwind_config_file.is_some() {
19 bail!("The Cargo.toml `tailwind-input-file` is required when using `tailwind-config-file`]");
20 }
21 return Ok(None);
22 };
23
24 let is_v_4 = VersionConfig::Tailwind.version().starts_with("v4");
25
26 let config_file = if is_v_4 {
27 if conf.tailwind_config_file.is_some()
28 || conf.config_dir.join("tailwind.config.js").exists()
29 {
30 info!("JavaScript config files are no longer required in Tailwind CSS v4. If you still need to use a JS config file, refer to the docs here: https://tailwindcss.com/docs/upgrade-guide#using-a-javascript-config-file.");
31 }
32
33 conf.tailwind_config_file.clone()
34 } else {
35 Some(
36 conf.config_dir.join(
37 conf.tailwind_config_file
38 .clone()
39 .unwrap_or_else(|| Utf8PathBuf::from("tailwind.config.js")),
40 ),
41 )
42 };
43
44 let tmp_file = conf.tmp_dir.join("tailwind.css");
45
46 Ok(Some(Self {
47 input_file,
48 config_file,
49 tmp_file,
50 }))
51 }
52}