STX Templating Engine
STX is the full-stack templating and component framework for Stacks. It handles template rendering, reactivity, SSR, streaming, hydration, and more.
Key Paths
- STX config:
config/stx.ts
- STX plugin:
bun-plugin-stx (loaded via bunfig.toml)
- STX state:
.stx/
- Components:
resources/components/
- Layouts:
resources/layouts/
- Partials:
resources/partials/
- Views:
resources/views/
- Package:
@stacksjs/stx
CRITICAL Rules
- ALWAYS use STX for templating — never write vanilla JS
- NEVER use
var, document.*, window.* in STX templates
- STX
<script> tags should ONLY contain stx-compatible code (signals, composables, directives)
Template Structure
<template>
<div class="container">
<h1>{{ title }}</h1>
<p x-if="showDescription">{{ description }}</p>
<button @click="increment">Count: {{ count }}</button>
</div>
</template>
<script>
import { ref, computed } from '@stacksjs/composables'
const count = ref(0)
const title = ref('Hello STX')
const showDescription = ref(true)
function increment() {
count.value++
}
</script>
<style>
/* Use crosswind utility classes or custom CSS */
.container { max-width: 1200px; margin: 0 auto; }
</style>
Configuration (config/stx.ts)
import type { StxOptions } from '@stacksjs/stx'
export default {
componentsDir: 'resources/components',
layoutsDir: 'resources/layouts',
partialsDir: 'resources/partials',
} satisfies StxOptions
Full StxConfig
interface StxConfig {
enabled: boolean
debug: boolean
componentsDir: string
partialsDir: string
layoutsDir?: string
defaultLayout?: string
templatesDir?: string
cachePath: string
ssr?: boolean
cache?: boolean
defaultTitle?: string
defaultDescription?: string
// Feature modules
i18n?: Partial<I18nConfig>
webComponents?: Partial<WebComponentConfig>
streaming?: Partial<StreamingConfig>
hydration?: Partial<HydrationConfig>
a11y?: Partial<A11yConfig>
seo?: Partial<SeoFeatureConfig>
animation?: Partial<AnimationConfig>
markdown?: Partial<MarkdownConfig>
forms?: Partial<FormConfig>
pwa?: Partial<PwaConfig>
components?: Partial<ComponentConfig>
media?: Partial<MediaConfig>
strict?: boolean | StrictModeConfig
customDirectives?: CustomDirective[]
}
STX Capabilities (118+ modules)
Core
- Template parsing and compilation
- Reactivity system (ref, computed, watch)
- Component composition and lifecycle
- Dependency injection (provide/inject)
Rendering
- SSR — Server-Side Rendering
- Streaming — Progressive HTML streaming
- Hydration — Progressive and islands-based hydration
- Suspense — Async component loading with fallbacks
- Error boundaries — Graceful error handling in components
Features
- Router — Client-side routing
- Forms — Built-in form handling and validation
- i18n — Internationalization support
- SEO — Meta tags, Open Graph, Twitter cards, structured data
- PWA — Progressive Web App support
- Animation — CSS and JS animation system
- Markdown — Markdown rendering with syntax highlighting
- A11y — Accessibility checking and auto-fixing
Dev Tools
- Dev server with HMR (Hot Module Replacement)
- Image optimization
- Asset pipeline
- Testing utilities
Plugin Loading
# bunfig.toml
[serve]
plugins = ["bun-plugin-stx"]
The STX plugin processes .stx files during serve and build.
Scaffolding
import { createProject, addComponent, addPage, addStore, addLayout } from '@stacksjs/stx'
// Create a new project
await createProject('my-app', { template: 'dashboard' })
// Add to existing project
await addComponent('UserCard', { props: true, styles: true })
await addPage('about', { layout: 'default' })
await addStore('cart', { persist: true, actions: true })
await addLayout('admin', { nav: true, footer: true })
Project Templates
default, minimal, full, blog, dashboard, landing
Gotchas
- STX is the ONLY templating system — do not use other template engines
bun-plugin-stx must be loaded — without it, .stx files won't be processed
- Auto-imports — browser auto-imports defined in
storage/framework/browser-auto-imports.json
.stx/ directory — contains STX-specific state and cache
- Reactivity is custom —
ref() and computed() from STX are not Vue's implementation
- Crosswind for styling — use utility classes, not inline styles
- Script block restrictions — only stx-compatible code (signals, composables, directives), no vanilla DOM APIs
- Components go in
resources/ — not in app/ or storage/
- 118+ modules — STX is a comprehensive framework covering rendering, routing, forms, i18n, SEO, PWA, and more
1---2name: stacks-stx-43description: Use when working with STX templates in a Stacks application — template syntax, components, directives, signals, reactivity, SSR, streaming, hydration, or debugging STX rendering. STX is the ONLY templating system for Stacks.4license: MIT5---67# STX Templating Engine89STX is the full-stack templating and component framework for Stacks. It handles template rendering, reactivity, SSR, streaming, hydration, and more.1011## Key Paths12- STX config: `config/stx.ts`13- STX plugin: `bun-plugin-stx` (loaded via bunfig.toml)14- STX state: `.stx/`15- Components: `resources/components/`16- Layouts: `resources/layouts/`17- Partials: `resources/partials/`18- Views: `resources/views/`19- Package: `@stacksjs/stx`2021## CRITICAL Rules221. **ALWAYS use STX** for templating — never write vanilla JS232. **NEVER use** `var`, `document.*`, `window.*` in STX templates243. STX `<script>` tags should ONLY contain stx-compatible code (signals, composables, directives)2526## Template Structure2728```html29<template>30 <div class="container">31 <h1>{{ title }}</h1>32 <p x-if="showDescription">{{ description }}</p>33 <button @click="increment">Count: {{ count }}</button>34 </div>35</template>3637<script>38import { ref, computed } from '@stacksjs/composables'3940const count = ref(0)41const title = ref('Hello STX')42const showDescription = ref(true)4344function increment() {45 count.value++46}47</script>4849<style>50/* Use crosswind utility classes or custom CSS */51.container { max-width: 1200px; margin: 0 auto; }52</style>53```5455## Configuration (config/stx.ts)5657```typescript58import type { StxOptions } from '@stacksjs/stx'5960export default {61 componentsDir: 'resources/components',62 layoutsDir: 'resources/layouts',63 partialsDir: 'resources/partials',64} satisfies StxOptions65```6667### Full StxConfig6869```typescript70interface StxConfig {71 enabled: boolean72 debug: boolean73 componentsDir: string74 partialsDir: string75 layoutsDir?: string76 defaultLayout?: string77 templatesDir?: string78 cachePath: string79 ssr?: boolean80 cache?: boolean81 defaultTitle?: string82 defaultDescription?: string8384 // Feature modules85 i18n?: Partial<I18nConfig>86 webComponents?: Partial<WebComponentConfig>87 streaming?: Partial<StreamingConfig>88 hydration?: Partial<HydrationConfig>89 a11y?: Partial<A11yConfig>90 seo?: Partial<SeoFeatureConfig>91 animation?: Partial<AnimationConfig>92 markdown?: Partial<MarkdownConfig>93 forms?: Partial<FormConfig>94 pwa?: Partial<PwaConfig>95 components?: Partial<ComponentConfig>96 media?: Partial<MediaConfig>97 strict?: boolean | StrictModeConfig98 customDirectives?: CustomDirective[]99}100```101102## STX Capabilities (118+ modules)103104### Core105- Template parsing and compilation106- Reactivity system (ref, computed, watch)107- Component composition and lifecycle108- Dependency injection (provide/inject)109110### Rendering111- **SSR** — Server-Side Rendering112- **Streaming** — Progressive HTML streaming113- **Hydration** — Progressive and islands-based hydration114- **Suspense** — Async component loading with fallbacks115- **Error boundaries** — Graceful error handling in components116117### Features118- **Router** — Client-side routing119- **Forms** — Built-in form handling and validation120- **i18n** — Internationalization support121- **SEO** — Meta tags, Open Graph, Twitter cards, structured data122- **PWA** — Progressive Web App support123- **Animation** — CSS and JS animation system124- **Markdown** — Markdown rendering with syntax highlighting125- **A11y** — Accessibility checking and auto-fixing126127### Dev Tools128- **Dev server** with HMR (Hot Module Replacement)129- **Image optimization**130- **Asset pipeline**131- **Testing utilities**132133## Plugin Loading134135```toml136# bunfig.toml137[serve]138plugins = ["bun-plugin-stx"]139```140141The STX plugin processes `.stx` files during serve and build.142143## Scaffolding144145```typescript146import { createProject, addComponent, addPage, addStore, addLayout } from '@stacksjs/stx'147148// Create a new project149await createProject('my-app', { template: 'dashboard' })150151// Add to existing project152await addComponent('UserCard', { props: true, styles: true })153await addPage('about', { layout: 'default' })154await addStore('cart', { persist: true, actions: true })155await addLayout('admin', { nav: true, footer: true })156```157158### Project Templates159`default`, `minimal`, `full`, `blog`, `dashboard`, `landing`160161## Gotchas162- **STX is the ONLY templating system** — do not use other template engines163- **`bun-plugin-stx` must be loaded** — without it, `.stx` files won't be processed164- **Auto-imports** — browser auto-imports defined in `storage/framework/browser-auto-imports.json`165- **`.stx/` directory** — contains STX-specific state and cache166- **Reactivity is custom** — `ref()` and `computed()` from STX are not Vue's implementation167- **Crosswind for styling** — use utility classes, not inline styles168- **Script block restrictions** — only stx-compatible code (signals, composables, directives), no vanilla DOM APIs169- **Components go in `resources/`** — not in `app/` or `storage/`170- **118+ modules** — STX is a comprehensive framework covering rendering, routing, forms, i18n, SEO, PWA, and more