Config¶
Litestar-Vite Configuration.
This module provides the configuration dataclasses for the Vite integration. The configuration is split into logical groups:
PathConfig: File system paths
RuntimeConfig: Execution settings
TypeGenConfig: Type generation settings
ViteConfig: Root configuration combining all sub-configs
Example usage:
# Minimal - SPA mode with defaults
VitePlugin(config=ViteConfig())
# Development mode
VitePlugin(config=ViteConfig(dev_mode=True))
# With type generation
VitePlugin(config=ViteConfig(dev_mode=True, types=True))
# Template mode for HTMX
VitePlugin(config=ViteConfig(mode="template", dev_mode=True))
- class litestar_vite.config.DeployConfig[source]¶
Bases:
objectCDN deployment configuration.
- storage_options¶
Provider options forwarded to
fsspec(credentials, region, etc.).
- __init__(enabled: bool = False, storage_backend: str | None = <factory>, storage_options: dict[str, ~typing.Any] = <factory>, delete_orphaned: bool = <factory>, include_manifest: bool = True, content_types: dict[str, str] = <factory>) None¶
- class litestar_vite.config.PathConfig[source]¶
Bases:
objectFile system paths configuration.
- class litestar_vite.config.RuntimeConfig[source]¶
Bases:
objectRuntime execution settings.
- protocol¶
Protocol for dev server (http/https).
- Type:
Literal[‘http’, ‘https’]
- executor¶
JavaScript runtime executor (node, bun, deno).
- Type:
Literal[‘node’, ‘bun’, ‘deno’, ‘yarn’, ‘pnpm’] | None
- proxy_mode¶
Proxy mode for dev server requests.
- Type:
Literal[‘proxy’, ‘direct’]
- http2¶
Enable HTTP/2 for proxy HTTP requests (better multiplexing). WebSocket traffic (HMR) uses a separate connection and is unaffected.
- Type:
- __init__(dev_mode: bool = <factory>, hot_reload: bool = <factory>, host: str = <factory>, port: int = <factory>, protocol: ~typing.Literal['http', 'https'] = 'http', executor: ~typing.Literal['node', 'bun', 'deno', 'yarn', 'pnpm'] | None = None, run_command: list[str] | None = None, build_command: list[str] | None = None, build_watch_command: list[str] | None = None, install_command: list[str] | None = None, is_react: bool = False, ssr_enabled: bool = False, health_check: bool = <factory>, detect_nodeenv: bool = False, set_environment: bool = True, set_static_folders: bool = True, csp_nonce: str | None = None, proxy_mode: ~typing.Literal['proxy', 'direct'] = <factory>, spa_handler: bool = True, http2: bool = True) None¶
- class litestar_vite.config.SPAConfig[source]¶
Bases:
objectConfiguration for SPA HTML transformations.
This configuration controls how the SPA HTML is transformed before serving, including route metadata injection, CSRF token injection, and Inertia.js page data handling.
- routes_exclude¶
Blacklist patterns for route filtering (None = exclude none).
- cache_transformed_html¶
Cache transformed HTML in production; disabled when inject_csrf=True because CSRF tokens are per-request.
- Type:
- __init__(inject_routes: bool = True, inject_csrf: bool = True, routes_var_name: str = '__LITESTAR_ROUTES__', csrf_var_name: str = '__LITESTAR_CSRF__', routes_include: list[str] | None = <factory>, routes_exclude: list[str] | None = <factory>, app_selector: str = '#app', cache_transformed_html: bool = True) None¶
- class litestar_vite.config.TypeGenConfig[source]¶
Bases:
objectType generation settings.
- output¶
Output directory for generated types.
- Type:
- openapi_path¶
Path to export OpenAPI schema.
- Type:
- routes_path¶
Path to export routes metadata.
- Type:
- class litestar_vite.config.ViteConfig[source]¶
Bases:
objectRoot Vite configuration.
This is the main configuration class that combines all sub-configurations. Supports shortcuts for common configurations:
dev_mode: Shortcut for runtime.dev_mode
types=True: Enable type generation with defaults
inertia=True: Enable Inertia.js with defaults
Mode auto-detection:
If mode is not explicitly set:
Checks for index.html in resource_dir -> SPA mode
Checks if Jinja2 template engine is configured -> Template mode
Otherwise defaults to SPA mode
Explicit mode parameter overrides auto-detection
- mode¶
Serving mode - “spa”, “template”, or “htmx”. Auto-detected if not set.
- Type:
Literal[‘spa’, ‘template’, ‘htmx’] | None
- paths¶
File system paths configuration.
- runtime¶
Runtime execution settings.
- types¶
Type generation settings (True enables with defaults).
- Type:
- inertia¶
Inertia.js settings (True enables with defaults).
- Type:
- spa¶
SPA transformation settings (True enables with defaults, False disables).
- deploy¶
Deployment configuration for CDN publishing.
- Type:
- validate_mode() None[source]¶
Validate the mode configuration against the project structure.
- Raises:
ValueError – If the configuration is invalid for the selected mode.
- property executor: JSExecutor¶
Get the JavaScript executor instance.
- property proxy_mode: Literal['proxy', 'direct']¶
Get proxy mode (proxy=single-port via ASGI, direct=expose Vite port).
- property spa_config: SPAConfig | None¶
Get SPA configuration if enabled, or None if disabled.
- Returns:
SPAConfig instance if spa transformations are enabled, None otherwise.
- property deploy_config: DeployConfig | None¶
Get deploy configuration if enabled.
- Returns:
DeployConfig instance when deployment is configured, None otherwise.
- __init__(mode: Literal['spa', 'template', 'htmx'] | None = None, paths: ~litestar_vite.config.PathConfig = <factory>, runtime: ~litestar_vite.config.RuntimeConfig = <factory>, types: TypeGenConfig | bool = <factory>, inertia: InertiaConfig | bool = False, spa: SPAConfig | bool | None = None, dev_mode: bool = False, base_url: str | None = <factory>, deploy: DeployConfig | bool = False, _executor_instance: JSExecutor | None = None, _mode_auto_detected: bool = False) None¶