Skip to content

Feature Request: Integrate Rust-based CSS Generator into tailwind-rs-core #2

Description

@petehanssens

🎯 Feature Request: Rust-based CSS Generator

Problem Statement

Currently, tailwind-rs-core generates classes at runtime, but Tailwind's JIT compiler only includes classes it finds in source files. This creates a gap where:

  • Generated classes from ClassBuilder aren't visible in the final CSS
  • Users need external tools or manual CSS management
  • No seamless integration between class generation and CSS compilation

Proposed Solution

Integrate a Rust-based CSS generator directly into tailwind-rs-core that:

  • Generates comprehensive CSS files with all necessary Tailwind classes
  • Works seamlessly with existing ClassBuilder API
  • Eliminates need for external tools or CDN dependencies
  • Provides type-safe, Rust-native CSS generation

Proposed API

use tailwind_rs_core::*;

// Generate classes
let classes = ClassBuilder::new()
    .padding(SpacingValue::Integer(4))
    .background_color(Color::new(ColorPalette::Blue, ColorShade::Shade100))
    .build();

// NEW: Auto-generate CSS with all classes
tailwind_rs_core::generate_css_file("styles.css", &classes)?;

// Advanced usage
let mut generator = CssGenerator::new()
    .include_color_palettes(vec!["blue", "gray", "purple"])
    .include_spacing(true)
    .include_typography(true)
    .include_shadows(true);

generator.generate_css_file("comprehensive.css")?;

Benefits

  • Seamless integration - No external tools needed
  • Type safety - Everything in Rust
  • Performance - Generate once, serve many
  • Flexibility - Configurable generation
  • Framework agnostic - Works with Leptos, Dioxus, Yew, etc.

Implementation Details

We have already developed a working prototype that:

  • Generates comprehensive CSS with all Tailwind classes
  • Includes color palettes, spacing, typography, shadows, etc.
  • Integrates with existing ClassBuilder API
  • Provides configuration options for what to include

Use Case Example

// Current workflow (problematic)
let classes = ClassBuilder::new()
    .background_color(Color::new(ColorPalette::Blue, ColorShade::Shade100))
    .build();
// Classes generated but not visible in final CSS

// Proposed workflow (seamless)
let classes = ClassBuilder::new()
    .background_color(Color::new(ColorPalette::Blue, ColorShade::Shade100))
    .build();

// Generate CSS file with all necessary classes
tailwind_rs_core::generate_css_file("target/site/pkg/styles.css", &classes)?;
// Now all classes are available in the CSS file

Why This Belongs in tailwind-rs-core

  • Solves a real problem that affects many users
  • Fits the crate's purpose of Tailwind + Rust integration
  • Complements existing ClassBuilder functionality
  • Reduces ecosystem fragmentation
  • Provides a complete, type-safe solution

Next Steps

  1. Move CSS generator logic into tailwind-rs-core
  2. Add proper configuration options
  3. Write comprehensive tests
  4. Update documentation with examples
  5. Release as part of the core crate

This would make tailwind-rs-core a complete solution for Tailwind CSS in Rust applications! 🚀

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions