Skip to content
avocardowPublic

About

Your HTML and JavaScript files are full of repetitive Tailwind class combinations. This tool finds those patterns and replaces them with tiny class names while generating the CSS to make it work.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

292 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Tailwind Enigma

CI Release License: MIT Tests

Dramatically shrink your HTML and JavaScript bundle sizes by replacing repetitive Tailwind class patterns with short, optimized class names.


What does this do? πŸ€”

Simple answer: Your HTML and JavaScript files are full of repetitive Tailwind class combinations like "flex items-center justify-center text-white bg-blue-500 px-4 py-2 rounded". This tool finds those patterns and replaces them with tiny class names like "ab" while generating the CSS to make it work.

Before Tailwind Enigma:

<!-- This pattern repeats 50 times in your app -->
<div class="flex items-center justify-center text-white bg-blue-500 px-4 py-2 rounded">Button</div>
<div class="flex items-center justify-center text-white bg-blue-500 px-4 py-2 rounded">
  Another Button
</div>
<div class="flex items-center justify-center text-white bg-blue-500 px-4 py-2 rounded">
  Yet Another
</div>

<!-- Your bundle: 4,200 characters just for classes 😱 -->

After Tailwind Enigma:

<!-- Same pattern now uses tiny class names -->
<div class="ab">Button</div>
<div class="ab">Another Button</div>
<div class="ab">Yet Another</div>

<!-- Your bundle: 150 characters πŸŽ‰ -->
<!-- Plus generated CSS: .ab { @apply flex items-center justify-center text-white bg-blue-500 px-4 py-2 rounded; } -->

Result: 97% smaller HTML/JS bundles! ⚑


30-Second Quick Start ⚑

# 1. Install it
npm install @tw-enigma/cli

# 2. Initialize configuration
npx enigma init

# 3. Analyze your project
npx enigma analyze

# 4. Generate optimized CSS
npx enigma generate

# Done! Your project now uses optimized atomic CSS

What just happened?

  1. πŸ” Scanned your files - Found every Tailwind class combination
  2. πŸ“Š Counted patterns - Identified which combinations appear most often
  3. βœ‚οΈ Generated atomic CSS - Created optimized classes based on usage patterns
  4. 🎯 Optimized your build - Reduced CSS bundle size dramatically
  5. πŸš€ Smaller bundles - Your users download way less code!

πŸ”§ CLI Global Options

The @tw-enigma/cli supports several global options that work with all commands:

Class Name Generation

  • --length <number> - Set minimum class name length (1-26)

    # Generate longer class names for better obfuscation
    npx enigma --length 8 init
    npx enigma --length 12 generate
    
    # Use with any command
    npx enigma --length 5 analyze --report

Output Control

  • --verbose - Enable detailed logging and debug information
  • --debug - Enable debug mode with comprehensive diagnostics
  • --pretty - Format output for better readability
  • --quiet - Suppress all output except warnings and errors

Configuration

  • --config <path> - Specify custom configuration file path
  • --input <path> - Override input directory
  • --output <path> - Override output directory

Performance

  • --max-concurrency <number> - Control parallel processing
  • --exclude-patterns <patterns...> - Exclude files from processing

Example Usage

# Enhanced security with longer class names
npx enigma --length 10 --verbose generate

# Custom configuration with performance tuning
npx enigma --config custom.config.js --max-concurrency 8 analyze

# Development workflow with detailed output
npx enigma --length 6 --pretty --debug init

πŸ“Š Security Benefits of Longer Class Names:

Length Combinations Security Level
1-3 <18K Basic
4-6 18K-17M Moderate
7-10 17M-3.7T High
11+ >3.7T Maximum

πŸ“¦ Packages

This monorepo contains the following packages:

Package Version Description
@tw-enigma/core npm version Core CSS optimization engine with pattern analysis and generation
@tw-enigma/cli npm version Command-line interface for tw-enigma operations

πŸ”§ Core Package

The heart of the optimization engine, providing:

  • CSS pattern analysis and frequency detection
  • Atomic class generation with semantic naming
  • Build tool plugins (Vite, Webpack, PostCSS)
  • Development tools and debugging utilities
  • Performance monitoring and optimization metrics

πŸ’» CLI Package

Command-line tools for:

  • Project analysis and optimization
  • Configuration management
  • Performance benchmarking
  • Development workflow integration

πŸ—οΈ Development

Monorepo Structure

tw-enigma/
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ core/                 # Core optimization engine
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ dist/
β”‚   β”‚   └── package.json
β”‚   └── cli/                  # Command-line interface
β”‚       β”œβ”€β”€ src/
β”‚       β”œβ”€β”€ bin/
β”‚       └── package.json
β”œβ”€β”€ docs/                     # Documentation
β”œβ”€β”€ examples/                 # Usage examples
β”œβ”€β”€ .github/                  # GitHub Actions workflows
β”œβ”€β”€ .changeset/              # Changeset configuration
└── turbo.json               # Turborepo configuration

Setup Development Environment

  1. Clone the repository:

    git clone https://github.com/avocardow/tw-enigma.git
    cd tw-enigma
  2. Install dependencies:

    pnpm install
  3. Build all packages:

    pnpm build
  4. Run tests:

    pnpm test

Development Workflow

Working with Specific Packages
# Start development mode for core package
pnpm --filter @tw-enigma/core dev

# Run tests for CLI package
pnpm --filter @tw-enigma/cli test

# Build only the core package
pnpm --filter @tw-enigma/core build
Running Common Tasks
# Lint all packages
pnpm lint

# Type check all packages
pnpm type-check

# Run all tests
pnpm test

# Clean all build artifacts
pnpm clean
Working with the Demo

The project includes a Next.js demo application with Enigma integration:

Development Mode:

# Run the demo with Enigma optimization enabled
pnpm dev:enigma

# Run the demo in normal mode (without Enigma)
pnpm dev:demo

Production Mode:

# Build the demo with Enigma optimization
pnpm build:enigma

# Build the demo in normal mode
pnpm build:demo

# Start the production server (after building)
pnpm start

Complete Workflow to See Enigma's Effects:

# 1. Build with Enigma optimizations
pnpm build:enigma

# 2. Start the production server
pnpm start

# 3. Open http://localhost:3000 to see the optimized site

These scripts allow you to test Enigma functionality without having to navigate to the demo directory.

Using Turbo for Efficient Builds

This project uses Turborepo for intelligent task execution:

# Build with caching
pnpm turbo build

# Run tests with parallelization
pnpm turbo test

# Clear Turbo cache
pnpm turbo prune

Code Quality

We maintain high code quality standards through:

  • ESLint for code linting
  • Prettier for code formatting
  • TypeScript for type safety
  • Vitest for comprehensive testing
  • Changesets for version management

πŸ“š Documentation

Developer Documentation


🀝 Contributing

We welcome contributions from the community! Here's how to get started:

  1. Read our Contributing Guidelines
  2. Check out good first issues
  3. Join our Discord community (placeholder)

Development Process

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for your changes
  5. Run the test suite: pnpm test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to your branch: git push origin feature/amazing-feature
  8. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Your HTML and JavaScript files are full of repetitive Tailwind class combinations. This tool finds those patterns and replaces them with tiny class names while generating the CSS to make it work.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages