Dramatically shrink your HTML and JavaScript bundle sizes by replacing repetitive Tailwind class patterns with short, optimized class names.
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! β‘
# 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 CSSWhat just happened?
- π Scanned your files - Found every Tailwind class combination
- π Counted patterns - Identified which combinations appear most often
- βοΈ Generated atomic CSS - Created optimized classes based on usage patterns
- π― Optimized your build - Reduced CSS bundle size dramatically
- π Smaller bundles - Your users download way less code!
The @tw-enigma/cli supports several global options that work with all commands:
-
--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
--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
--config <path>- Specify custom configuration file path--input <path>- Override input directory--output <path>- Override output directory
--max-concurrency <number>- Control parallel processing--exclude-patterns <patterns...>- Exclude files from processing
# 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 |
This monorepo contains the following packages:
| Package | Version | Description |
|---|---|---|
@tw-enigma/core |
Core CSS optimization engine with pattern analysis and generation | |
@tw-enigma/cli |
Command-line interface for tw-enigma operations |
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
Command-line tools for:
- Project analysis and optimization
- Configuration management
- Performance benchmarking
- Development workflow integration
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
-
Clone the repository:
git clone https://github.com/avocardow/tw-enigma.git cd tw-enigma -
Install dependencies:
pnpm install
-
Build all packages:
pnpm build
-
Run tests:
pnpm test
# 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# Lint all packages
pnpm lint
# Type check all packages
pnpm type-check
# Run all tests
pnpm test
# Clean all build artifacts
pnpm cleanThe 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:demoProduction 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 startComplete 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 siteThese scripts allow you to test Enigma functionality without having to navigate to the demo directory.
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 pruneWe 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
We welcome contributions from the community! Here's how to get started:
- Read our Contributing Guidelines
- Check out good first issues
- Join our Discord community (placeholder)
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests for your changes
- Run the test suite:
pnpm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to your branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.