typewritingclass-compiler
v0.3.2
Published
Static CSS extraction compiler and Vite plugin for typewritingclass
Downloads
1,351
Maintainers
Readme
typewritingclass-compiler
Rust-powered compiler and Vite plugin for Typewriting Class. Statically analyzes TypeScript source files, extracts CSS at build time, and replaces utility calls with generated class names — producing zero-runtime CSS output.
Installation
bun add -d typewritingclass-compilerVite Plugin
// vite.config.ts
import { defineConfig } from 'vite'
import twcPlugin from 'typewritingclass-compiler'
export default defineConfig({
plugins: [twcPlugin()],
})Add your framework plugin alongside it. For Solid.js, twcPlugin() must come first — vite-plugin-solid also uses enforce: 'pre' and rewrites import paths before the compiler can identify them if it runs first:
plugins: [twcPlugin(), solid()] // Solid — order matters
plugins: [react(), twcPlugin()] // React — order doesn't matterThen import the virtual CSS module:
import 'virtual:twc.css'Options
twcPlugin({
strict: true, // Error on dynamic values not wrapped with dynamic() (default: true)
})How it works
- Static analysis — the Rust extractor scans TS/JS files for
tw,cx(),when(), and utility calls - CSS generation — extracted rules are compiled into deterministic class names and CSS declarations
- Code transform — utility call sites are replaced with the generated class name strings
- Virtual module —
virtual:twc.cssaggregates all extracted CSS, respecting@layerordering - Dynamic fallback — values that can't be statically resolved fall back to runtime CSS custom properties
Strict mode
Strict mode (default) requires dynamic values to be explicitly wrapped with dynamic(). This makes the boundary between static and runtime CSS explicit. Set strict: false to allow implicit dynamic values.
Exports
| Export | Description |
|---|---|
| default | Vite plugin factory |
| nativeTransform | Core transform function (Rust via NAPI) |
| generateCss | CSS aggregation utility |
| ThemeInput | Theme configuration type |
| TransformOutput | Transform result type |
| ExtractedRule | Individual extracted rule type |
| Diagnostic | Compiler diagnostic type |
