#[derive(Debug, Clone)]
pub struct CssPluginOptions {
pub minify: bool,
pub targets: Option<Vec<String>>,
pub source_map: bool,
pub exclude: Vec<String>,
pub include: Vec<String>,
}
impl Default for CssPluginOptions {
fn default() -> Self {
Self {
minify: false,
targets: None,
source_map: false,
exclude: vec!["**/*.min.css".to_string()],
include: Vec::new(),
}
}
}
impl CssPluginOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_minify(mut self, enabled: bool) -> Self {
self.minify = enabled;
self
}
pub fn with_targets(mut self, targets: Vec<String>) -> Self {
self.targets = Some(targets);
self
}
pub fn with_source_maps(mut self, enabled: bool) -> Self {
self.source_map = enabled;
self
}
pub fn exclude(mut self, pattern: impl Into<String>) -> Self {
self.exclude.push(pattern.into());
self
}
pub fn include(mut self, pattern: impl Into<String>) -> Self {
self.include.push(pattern.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_options() {
let opts = CssPluginOptions::default();
assert_eq!(opts.minify, false);
assert!(opts.targets.is_none());
assert_eq!(opts.source_map, false);
assert!(!opts.exclude.is_empty());
}
#[test]
fn test_builder_pattern() {
let opts = CssPluginOptions::new()
.with_minify(true)
.with_targets(vec![">0.2%".to_string()])
.with_source_maps(true);
assert!(opts.minify);
assert!(opts.targets.is_some());
assert!(opts.source_map);
}
#[test]
fn test_exclusion_patterns() {
let opts = CssPluginOptions::new()
.exclude("vendor/**")
.exclude("node_modules/**");
assert!(opts.exclude.iter().any(|p| p.contains("vendor")));
}
}