Vite plugin for Tomato CSS - import .tom files in React with scoped styles
npm install vite-plugin-tomatoVite plugin for Tomato CSS - Write human-friendly CSS with automatic scoping.
- 🎯 Scoped Styles - Styles are automatically scoped to components
- ⚡ Hot Reload - Instant updates when you edit .tom files
- 🧩 Simple API - Just wrap your component with withTomato()
- 📦 Zero Config - Works out of the box
``bash`
npm install vite-plugin-tomato @srivtx/tomato-css
Add the plugin to your vite.config.js:
`javascript
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tomato from 'vite-plugin-tomato';
export default defineConfig({
plugins: [react(), tomato()]
});
`
``
// Button.tom
.btn:
bg blue-500
text white
pad 2 4
round lg
hover:
bg blue-600
`jsx
// Button.jsx
import { withTomato } from './Button.tom';
function Button({ children }) {
return ;
}
export default withTomato(Button);
`
That's it! Your styles are automatically scoped to the Button component.
The plugin transforms your CSS selectors to be scoped:
`css
/ Your .tom file /
.btn { background: blue; }
/ Generated CSS /
[data-tom="t7a3b2c"] .btn { background: blue; }
`
The withTomato() HOC wraps your component with a scoping element:
`jsx`
This means two components can both use .btn without styles conflicting!
Higher-Order Component that wraps your component with scoped styles.
`jsx
import { withTomato } from './MyComponent.tom';
function MyComponent() {
return
export default withTomato(MyComponent);
`
Tomato CSS is a human-friendly CSS preprocessor:
| Tomato | CSS |
|--------|-----|
| bg blue-500 | background: #3b82f6; |text white
| | color: #ffffff; |pad 2 4
| | padding: 0.5rem 1rem; |round lg
| | border-radius: 0.5rem; |shadow md
| | box-shadow: ...;` |
See the full Tomato CSS documentation for more.
MIT © srivtx