-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
47 lines (43 loc) · 1.46 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::path::{Path, PathBuf};
use std::{env, process::Output};
use which::which;
// Example custom build script.
fn main() {
// Tell Cargo that if the given file changes, to rerun this build script.
println!("cargo:rerun-if-changed=templates/");
println!("cargo:rerun-if-changed=static/styles.css");
println!("cargo:rerun-if-changed=tailwind.config.js");
if let Some(exe) = find_tailwind() {
run_tailwind(&exe)
} else {
panic!("Tailwind CSS executable not found. Please download tailwindcss and either place it on your PATH or in the root of this Cargo project. https://tailwindcss.com/blog/standalone-cli ")
}
}
fn find_tailwind() -> Option<PathBuf> {
which("tailwindcss").ok().or_else(|| {
let pwd = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let path = pwd.join("tailwindcss");
path.exists().then_some(path.to_path_buf())
})
}
fn run_tailwind(exe: &Path) {
let result = std::process::Command::new(exe)
.arg("-i")
.arg("static/styles.css")
.arg("-o")
.arg("static/output.css")
.arg("--minify")
.output();
match result {
Ok(Output {
status,
stdout: _,
stderr,
}) if !status.success() => panic!(
"tailwindcss exited with error: {}",
String::from_utf8_lossy(&stderr)
),
Err(e) => panic!("Failed to run tailwindcss: {}", e),
_ => (),
}
}