@hua-labs/dot-aot
v0.1.0
Published
Build-time static extraction for @hua-labs/dot — Vite and Babel plugins
Downloads
57
Readme
@hua-labs/dot-aot
Build-time static extraction for @hua-labs/dot. Replaces static dot() calls with pre-computed style objects at build time, eliminating runtime parsing overhead. Provides a Vite plugin and a Babel plugin (Metro, Next.js compatible).
Features
- Zero-runtime CSS — static dot() calls replaced with inline object literals at build time
- Vite plugin — enforce: 'pre' transform hook, fast path skips files with no dot calls
- Babel plugin — AST-accurate CallExpression visitor, works with Metro and Next.js
- Regex-based extraction engine — skips calls in strings, comments, template literals, and chained methods
- Static options support — extracts target and dark when literal values; skips breakpoint (dynamic)
- Cross-platform output — correct serialization for web, native, and flutter targets
- Graceful fallback — malformed or unresolvable calls silently left as runtime
- styleToObjectLiteral — handles nested structures (RN transform arrays, Flutter recipe objects)
Installation
pnpm add @hua-labs/dot-aotPeer dependencies: vite >=5.0.0
Quick Start
// Vite
import dotAot from "@hua-labs/dot-aot/vite";
export default defineConfig({ plugins: [dotAot()] });
// Babel / Metro / Next.js
module.exports = {
plugins: [["@hua-labs/dot-aot/babel", { target: "native" }]],
};
// Before build:
const style = dot("p-4 flex items-center bg-primary-500");
// After build (inlined by plugin):
const style = {
padding: "16px",
display: "flex",
alignItems: "center",
backgroundColor: "var(--color-primary-500)",
};API
| Export | Type | Description |
| ------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| extractStaticCalls | function | Scan source string and return all extractable dot() calls sorted last-to-first. Options: { functionNames?: string[], target?: 'web' | 'native' | 'flutter' } |
| transformSource | function | Apply all extractions in a single pass. Returns { code, extractions } or null if no changes. Safe for use in any transform pipeline. |
| styleToObjectLiteral | function | Serialize a resolved style object to a JS object literal string (with wrapping parentheses). Handles nested arrays and objects for RN/Flutter targets. |
| ExtractedCall | type | { start: number; end: number; input: string; options?: DotOptions; result: Record<string, unknown> } |
| ExtractOptions | type | { functionNames?: string[]; target?: 'web' | 'native' | 'flutter' } |
| @hua-labs/dot-aot/vite subpath | | |
| dotAotVite (default) | function | Vite plugin factory. Returns a Vite plugin with enforce: 'pre'. Options: DotAotViteOptions. |
| DotAotViteOptions | type | Extends ExtractOptions. { include?: string[]; exclude?: string[] } — file extensions to include/exclude. |
| @hua-labs/dot-aot/babel subpath | | |
| dotAotBabel (default) | function | Babel plugin factory. Returns a Babel plugin with CallExpression visitor. Options: DotAotBabelOptions. |
| DotAotBabelOptions | type | { functionNames?: string[]; target?: DotTarget } |
Related Packages
License
MIT — HUA Labs
