webui
Programmatic Rust API for the WebUI build-time rendering framework. Parse templates, compile protocols, and render HTML — no CLI required.
Install
Quick Start
use ;
// Build a WebUI application from an app directory
let result = build?;
// result.protocol_bytes — serialized protocol (protobuf binary)
// result.css_files — extracted component CSS files
// result.component_asset_files — root/chunk `.webui.js` assets
// result.metafile — optional esbuild-compatible graph JSON
// result.stats — build timing and fragment counts
API
Build
| Function | Description |
|---|---|
build(options) |
Parse templates, discover components, compile protocol |
build_to_disk(options, out_dir) |
Build and write protocol.bin, CSS, and component assets to disk |
use ;
build_to_disk?;
For CDN/cache-friendly Link-mode CSS and static component assets, override the asset output fields:
BuildOptions
To emit lazy static component assets from Rust, set component_asset_roots and
use the WebUI plugin:
BuildOptions
Entry-reachable dependencies remain external to the asset graph, single-root
dependencies stay inline, and dependencies shared by the same multi-root
consumer set are emitted once as flat dynamic chunks. Asset-only component
records are removed from protocol.bin. Component assets cannot be combined
with <route>.
LegalComments::Inline is the default and preserves legal CSS comments
containing @license or @preserve, or starting with /*! or //!. Use
LegalComments::None to strip all HTML and CSS comments from build output.
Render
use ;
let protocol = from_protobuf?;
let state: Value = json!;
let handler = new;
handler.render?;
With a hydration plugin enabled (the webui plugin shown here; see the WebUI documentation for the available plugin identifiers):
use ;
use WebUIHydrationPlugin;
let handler = with_plugin;
Inspect
use ;
// From a file
let json = inspect?;
// From bytes
let json = inspect_bytes?;
Partial Responses (Client Navigation)
For servers handling client-side navigation, produce a complete JSON partial:
let partial = protocol.render_partial?;
// Returns: { state, templates, inventory, path, chain }
Types
| Type | Description |
|---|---|
BuildOptions |
Build configuration (app_dir, entry, css, plugin, components, css_file_name_template, css_public_base) |
BuildResult |
Build output (protocol, css_files, component_templates with metadata/closures, stats) |
BuildStats |
Build metrics (duration, fragment_count, protocol_size_bytes) |
Protocol |
Loaded immutable runtime protocol with reusable indices |
WebUIHandler |
Rendering engine (stateless, thread-safe) |
RenderOptions |
Render configuration (entry_id, request_path) |
ResponseWriter |
Trait for streaming rendered output |
CssStrategy |
CSS delivery mode (Link or Style) |
WebUIError |
Error type for build/inspect operations |
License
MIT