Vite plugin for Litestar
Project description
Litestar Vite
Litestar Vite connects the Litestar backend to a Vite toolchain. It supports SPA, Template, and Inertia flows, and can proxy Vite dev traffic through your ASGI port or run Vite directly.
Features
- One-port dev: proxies Vite HTTP + WS/HMR through Litestar by default; switch to two-port with
VITE_PROXY_MODE=direct. - SSR framework support: use
mode="ssr"for Astro, Nuxt, SvelteKit - proxies everything except your API routes. - Production assets: reads Vite manifest from
public/manifest.json(configurable) and serves underasset_url. - Type-safe frontends: optional OpenAPI/routes export +
@hey-api/openapi-tsvia the Vite plugin. - Inertia support: v2 protocol with session middleware and optional SPA mode.
Quick Start (SPA)
pip install litestar-vite
import os
from pathlib import Path
from litestar import Litestar
from litestar_vite import VitePlugin, ViteConfig, PathConfig
DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
app = Litestar(
plugins=[VitePlugin(config=ViteConfig(
dev_mode=DEV_MODE,
paths=PathConfig(root=Path(__file__).parent),
))]
)
litestar run --reload # Vite dev server is proxied automatically
Scaffold a frontend: litestar assets init --template vue (or react, svelte, htmx, react-inertia, vue-inertia, angular, astro, nuxt, sveltekit).
Development
To contribute or run the development project:
# Install all dependencies and build packages
make install && make build
# Install frontend dependencies for an example
uv run litestar --app-dir examples/vue-inertia assets install
# Run the development server
uv run litestar --app-dir examples/vue-inertia run
Replace vue-inertia with any other example: vue, react, svelte, react-inertia, htmx, angular, astro, nuxt, or sveltekit.
Template / HTMX
from pathlib import Path
from litestar import Litestar
from litestar.contrib.jinja import JinjaTemplateEngine
from litestar.template import TemplateConfig
from litestar_vite import VitePlugin, ViteConfig, PathConfig
here = Path(__file__).parent
app = Litestar(
template_config=TemplateConfig(directory=here / "templates", engine=JinjaTemplateEngine),
plugins=[VitePlugin(config=ViteConfig(
dev_mode=True,
paths=PathConfig(root=here),
))],
)
Inertia (v2)
Requires session middleware (32-char secret).
import os
from pathlib import Path
from litestar import Litestar
from litestar.middleware.session.client_side import CookieBackendConfig
from litestar_vite import VitePlugin, ViteConfig, PathConfig
from litestar_vite.inertia import InertiaConfig
here = Path(__file__).parent
SECRET_KEY = os.environ.get("SECRET_KEY", "development-only-secret-32-chars")
session = CookieBackendConfig(secret=SECRET_KEY.encode("utf-8"))
app = Litestar(
middleware=[session.middleware],
plugins=[VitePlugin(config=ViteConfig(
dev_mode=True,
paths=PathConfig(root=here),
inertia=InertiaConfig(root_template="index.html"),
))],
)
Meta-frameworks (Astro, Nuxt, SvelteKit)
Use mode="ssr" (or mode="framework") to proxy non-API routes to the framework's dev server:
import os
from pathlib import Path
from litestar import Litestar
from litestar_vite import VitePlugin, ViteConfig, PathConfig
here = Path(__file__).parent
DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
app = Litestar(
plugins=[
VitePlugin(config=ViteConfig(
mode="ssr",
dev_mode=DEV_MODE,
paths=PathConfig(root=here),
))
],
)
Proxy Modes
| Mode | Alias | Use Case |
|---|---|---|
vite |
- | SPAs - proxies Vite assets only (default) |
direct |
- | Two-port dev - expose Vite port directly |
proxy |
ssr |
Meta-frameworks - proxies everything except API routes |
Production Deployment
Astro (static): Astro generates static HTML by default. Build and serve with Litestar:
litestar --app-dir examples/astro assets install
litestar --app-dir examples/astro assets build
VITE_DEV_MODE=false litestar --app-dir examples/astro run
Nuxt/SvelteKit (SSR): These run their own Node servers. Deploy as two services:
# Terminal 1: SSR server
litestar --app-dir examples/nuxt assets build
litestar --app-dir examples/nuxt assets serve
# Terminal 2: Litestar API
VITE_DEV_MODE=false litestar --app-dir examples/nuxt run --port 8001
Type generation
VitePlugin(config=ViteConfig(types=True)) # enable exports
litestar assets generate-types # one-off or CI
CLI cheat sheet
litestar assets doctor— diagnose/fix configlitestar assets init --template react|vue|svelte|...— scaffold frontendlitestar assets build/serve— build or watchlitestar assets deploy --storage gcs://bucket/assets— upload via fsspeclitestar assets generate-types— OpenAPI + routes → TS typeslitestar assets install— install frontend deps with the configured executor
Doctor command highlights
- Prints Python vs Vite config snapshot (asset URLs, bundle/hot paths, ports, modes).
- Flags missing hot file (dev proxy), missing manifest (prod), type-gen exports, env/config mismatches, and plugin install issues.
--fixcan rewrite simple vite.config values (assetUrl, bundleDir, hotFile, type paths) after creating a backup.
Links
- Docs: https://litestar-org.github.io/litestar-vite/
- Examples:
examples/(react, vue, svelte, react-inertia, vue-inertia, astro, nuxt, sveltekit, htmx) - Real-world example: litestar-fullstack - Full-featured application using litestar-vite
- Issues: https://github.com/litestar-org/litestar-vite/issues/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litestar_vite-0.18.2.tar.gz.
File metadata
- Download URL: litestar_vite-0.18.2.tar.gz
- Upload date:
- Size: 410.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8885d7a4d9fd5aa90347c4aa916993b75c7492aab01719cbe26d1d938f5d32e9
|
|
| MD5 |
0972b9ca665e3ba27f86259eda9b5c87
|
|
| BLAKE2b-256 |
414dc28b131afbad33bf6c1cc08693df019e8d90f488e355720327051d53b701
|
Provenance
The following attestation bundles were made for litestar_vite-0.18.2.tar.gz:
Publisher:
publish.yml on litestar-org/litestar-vite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_vite-0.18.2.tar.gz -
Subject digest:
8885d7a4d9fd5aa90347c4aa916993b75c7492aab01719cbe26d1d938f5d32e9 - Sigstore transparency entry: 983811256
- Sigstore integration time:
-
Permalink:
litestar-org/litestar-vite@0cc4bbabd9f1cb505fbf115e88db0375ff610035 -
Branch / Tag:
refs/tags/v0.18.2 - Owner: https://github.com/litestar-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0cc4bbabd9f1cb505fbf115e88db0375ff610035 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litestar_vite-0.18.2-py3-none-any.whl.
File metadata
- Download URL: litestar_vite-0.18.2-py3-none-any.whl
- Upload date:
- Size: 227.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51837584ba957cfc9d446a3fc6419cca321e7d10498dbe583c798b142074d792
|
|
| MD5 |
d7e5cb9dbc508a4811686d68db8d2bc5
|
|
| BLAKE2b-256 |
c9e90f709a9cebdf386e1d8c2100250a67ee535b91ae40f5b004832d0b3c299f
|
Provenance
The following attestation bundles were made for litestar_vite-0.18.2-py3-none-any.whl:
Publisher:
publish.yml on litestar-org/litestar-vite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litestar_vite-0.18.2-py3-none-any.whl -
Subject digest:
51837584ba957cfc9d446a3fc6419cca321e7d10498dbe583c798b142074d792 - Sigstore transparency entry: 983811258
- Sigstore integration time:
-
Permalink:
litestar-org/litestar-vite@0cc4bbabd9f1cb505fbf115e88db0375ff610035 -
Branch / Tag:
refs/tags/v0.18.2 - Owner: https://github.com/litestar-org
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0cc4bbabd9f1cb505fbf115e88db0375ff610035 -
Trigger Event:
release
-
Statement type: