litestar-vite-plugin 0.15.0-alpha.3 → 0.15.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,66 +10,83 @@ Litestar Vite connects the Litestar backend to a Vite toolchain. It supports SPA
10
10
  - Type-safe frontends: optional OpenAPI/routes export + `@hey-api/openapi-ts` via the Vite plugin.
11
11
  - Inertia support: v2 protocol with session middleware and optional SPA mode.
12
12
 
13
- ## Quick start (React TanStack SPA)
13
+ ## Quick Start (SPA)
14
14
 
15
15
  ```bash
16
16
  pip install litestar-vite
17
- litestar assets init --template react-tanstack
18
- litestar assets install # installs frontend deps via configured executor
19
17
  ```
20
18
 
21
19
  ```python
20
+ import os
21
+ from pathlib import Path
22
22
  from litestar import Litestar
23
- from litestar_vite import VitePlugin, ViteConfig
23
+ from litestar_vite import VitePlugin, ViteConfig, PathConfig
24
+
25
+ DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
24
26
 
25
- app = Litestar(plugins=[VitePlugin(config=ViteConfig(dev_mode=True))]) # SPA mode by default
27
+ app = Litestar(
28
+ plugins=[VitePlugin(config=ViteConfig(
29
+ dev_mode=DEV_MODE,
30
+ paths=PathConfig(root=Path(__file__).parent),
31
+ ))]
32
+ )
26
33
  ```
27
34
 
28
35
  ```bash
29
- litestar run --reload # starts Litestar; Vite dev is proxied automatically
36
+ litestar run --reload # Vite dev server is proxied automatically
30
37
  ```
31
38
 
32
- Other templates: `react`, `vue`, `svelte`, `htmx`, `react-inertia`, `vue-inertia`, `svelte-inertia`, `angular`, `angular-cli`, `astro`, `nuxt`, `sveltekit` (see `litestar assets init --help`).
39
+ Scaffold a frontend: `litestar assets init --template vue` (or `react`, `svelte`, `htmx`, `react-inertia`, `vue-inertia`, `angular`, `astro`, `nuxt`, `sveltekit`).
33
40
 
34
41
  ## Template / HTMX
35
42
 
36
43
  ```python
44
+ from pathlib import Path
37
45
  from litestar import Litestar
38
46
  from litestar.contrib.jinja import JinjaTemplateEngine
39
- from litestar.template.config import TemplateConfig
40
- from litestar_vite import VitePlugin, ViteConfig
47
+ from litestar.template import TemplateConfig
48
+ from litestar_vite import VitePlugin, ViteConfig, PathConfig
49
+
50
+ here = Path(__file__).parent
41
51
 
42
52
  app = Litestar(
43
- template_config=TemplateConfig(engine=JinjaTemplateEngine(directory="templates")),
44
- plugins=[VitePlugin(config=ViteConfig(mode="template", dev_mode=True))],
53
+ template_config=TemplateConfig(directory=here / "templates", engine=JinjaTemplateEngine),
54
+ plugins=[VitePlugin(config=ViteConfig(
55
+ dev_mode=True,
56
+ paths=PathConfig(root=here),
57
+ ))],
45
58
  )
46
59
  ```
47
60
 
48
61
  ## Inertia (v2)
49
62
 
50
- Requires session middleware.
63
+ Requires session middleware (32-char secret).
51
64
 
52
65
  ```python
66
+ import os
67
+ from pathlib import Path
53
68
  from litestar import Litestar
54
69
  from litestar.middleware.session.client_side import CookieBackendConfig
55
- from litestar_vite import VitePlugin, ViteConfig
56
- from litestar_vite.inertia import InertiaPlugin
57
- from litestar_vite.inertia.config import InertiaConfig
70
+ from litestar_vite import VitePlugin, ViteConfig, PathConfig
71
+ from litestar_vite.inertia import InertiaConfig
58
72
 
59
- session_backend = CookieBackendConfig(secret="dev-secret")
73
+ here = Path(__file__).parent
74
+ SECRET_KEY = os.environ.get("SECRET_KEY", "development-only-secret-32-chars")
75
+ session = CookieBackendConfig(secret=SECRET_KEY.encode("utf-8"))
60
76
 
61
77
  app = Litestar(
62
- middleware=[session_backend.middleware],
63
- plugins=[
64
- VitePlugin(config=ViteConfig(mode="template", inertia=True, dev_mode=True)),
65
- InertiaPlugin(InertiaConfig()),
66
- ],
78
+ middleware=[session.middleware],
79
+ plugins=[VitePlugin(config=ViteConfig(
80
+ dev_mode=True,
81
+ paths=PathConfig(root=here),
82
+ inertia=InertiaConfig(root_template="index.html"),
83
+ ))],
67
84
  )
68
85
  ```
69
86
 
70
- ## SSR Frameworks (Astro, Nuxt, SvelteKit)
87
+ ## Meta-frameworks (Astro, Nuxt, SvelteKit)
71
88
 
72
- For SSR frameworks that handle their own routing, use `proxy_mode="ssr"`:
89
+ Use `proxy_mode="ssr"` to proxy non-API routes to the framework's dev server:
73
90
 
74
91
  ```python
75
92
  import os
@@ -77,17 +94,15 @@ from pathlib import Path
77
94
  from litestar import Litestar
78
95
  from litestar_vite import VitePlugin, ViteConfig, PathConfig, RuntimeConfig
79
96
 
97
+ here = Path(__file__).parent
80
98
  DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
81
99
 
82
100
  app = Litestar(
83
101
  plugins=[
84
102
  VitePlugin(config=ViteConfig(
85
103
  dev_mode=DEV_MODE,
86
- paths=PathConfig(root=Path(__file__).parent),
87
- runtime=RuntimeConfig(
88
- proxy_mode="ssr" if DEV_MODE else None, # Proxy in dev, static in prod
89
- spa_handler=not DEV_MODE, # Serve built files in production
90
- ),
104
+ paths=PathConfig(root=here),
105
+ runtime=RuntimeConfig(proxy_mode="ssr"),
91
106
  ))
92
107
  ],
93
108
  )
@@ -99,29 +114,28 @@ app = Litestar(
99
114
  |------|-------|----------|
100
115
  | `vite` | - | SPAs - proxies Vite assets only (default) |
101
116
  | `direct` | - | Two-port dev - expose Vite port directly |
102
- | `proxy` | `ssr` | SSR frameworks - proxies everything except API routes |
117
+ | `proxy` | `ssr` | Meta-frameworks - proxies everything except API routes |
103
118
 
104
119
  ### Production Deployment
105
120
 
106
- **Static Build (recommended):** Build your SSR framework to static files, then serve with Litestar:
121
+ **Astro (static):** Astro generates static HTML by default. Build and serve with Litestar:
107
122
 
108
123
  ```bash
109
- # Build frontend
110
- cd examples/astro && npm run build
111
-
112
- # Run in production mode
124
+ litestar --app-dir examples/astro assets install
125
+ litestar --app-dir examples/astro assets build
113
126
  VITE_DEV_MODE=false litestar --app-dir examples/astro run
114
127
  ```
115
128
 
116
- Configure `bundle_dir` to match your framework's build output:
129
+ **Nuxt/SvelteKit (SSR):** These run their own Node servers. Deploy as two services:
117
130
 
118
- | Framework | Default Output | PathConfig |
119
- |-----------|---------------|------------|
120
- | Astro | `dist/` | `bundle_dir=Path("dist")` |
121
- | Nuxt | `.output/public/` | `bundle_dir=Path(".output/public")` |
122
- | SvelteKit | `build/` | `bundle_dir=Path("build")` |
131
+ ```bash
132
+ # Terminal 1: SSR server
133
+ litestar --app-dir examples/nuxt assets build
134
+ litestar --app-dir examples/nuxt assets serve
123
135
 
124
- **Two-Service:** For dynamic SSR, run the Node server alongside Litestar behind a reverse proxy.
136
+ # Terminal 2: Litestar API
137
+ VITE_DEV_MODE=false litestar --app-dir examples/nuxt run --port 8001
138
+ ```
125
139
 
126
140
  ## Type generation
127
141
 
@@ -151,5 +165,5 @@ litestar assets generate-types # one-off or CI
151
165
  ## Links
152
166
 
153
167
  - Docs: <https://litestar-org.github.io/litestar-vite/>
154
- - Examples: `examples/` (basic, inertia, react)
168
+ - Examples: `examples/` (react, vue, svelte, react-inertia, vue-inertia, astro, nuxt, sveltekit, htmx)
155
169
  - Issues: <https://github.com/litestar-org/litestar-vite/issues/>
@@ -20,5 +20,5 @@
20
20
  *
21
21
  * @module
22
22
  */
23
- export { getCsrfToken, csrfHeaders, csrfFetch } from "./csrf.js";
24
- export { route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, LITESTAR, type RouteDefinition, type RoutesMap, type LitestarHelpers, } from "./routes.js";
23
+ export { csrfFetch, csrfHeaders, getCsrfToken } from "./csrf.js";
24
+ export { currentRoute, getRelativeUrlPath, getRoutes, isCurrentRoute, isRoute, LITESTAR, type LitestarHelpers, type RouteDefinition, type RoutesMap, route, toRoute, } from "./routes.js";
@@ -21,6 +21,6 @@
21
21
  * @module
22
22
  */
23
23
  // CSRF utilities
24
- export { getCsrfToken, csrfHeaders, csrfFetch } from "./csrf.js";
24
+ export { csrfFetch, csrfHeaders, getCsrfToken } from "./csrf.js";
25
25
  // Route utilities
26
- export { route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, LITESTAR, } from "./routes.js";
26
+ export { currentRoute, getRelativeUrlPath, getRoutes, isCurrentRoute, isRoute, LITESTAR, route, toRoute, } from "./routes.js";
@@ -1,4 +1,3 @@
1
- import { type ConfigEnv, type Plugin, type UserConfig } from "vite";
2
1
  import { type Config as FullReloadConfig } from "vite-plugin-full-reload";
3
2
  /**
4
3
  * Configuration for TypeScript type generation.
@@ -162,15 +161,13 @@ interface RefreshConfig {
162
161
  paths: string[];
163
162
  config?: FullReloadConfig;
164
163
  }
165
- interface LitestarPlugin extends Plugin {
166
- config: (config: UserConfig, env: ConfigEnv) => UserConfig;
167
- }
168
164
  type DevServerUrl = `${"http" | "https"}://${string}:${number}`;
169
165
  export declare const refreshPaths: string[];
170
166
  /**
171
167
  * Litestar plugin for Vite.
172
168
  *
173
169
  * @param config - A config object or relative path(s) of the scripts to be compiled.
170
+ * @returns An array of Vite plugins. Return type is `any[]` to avoid cross-version type conflicts.
174
171
  */
175
- export default function litestar(config: string | string[] | PluginConfig): [LitestarPlugin, ...Plugin[]];
172
+ export default function litestar(config: string | string[] | PluginConfig): any[];
176
173
  export {};
package/dist/js/index.js CHANGED
@@ -42,7 +42,7 @@ async function findIndexHtmlPath(server, pluginConfig) {
42
42
  }
43
43
  return null;
44
44
  }
45
- function normalizeAppUrl(appUrl, fallbackPort) {
45
+ function normalizeAppUrl(appUrl, _fallbackPort) {
46
46
  if (!appUrl || appUrl === "__litestar_app_url_missing__") {
47
47
  return { url: null, note: "APP_URL missing" };
48
48
  }
@@ -160,7 +160,7 @@ function resolveLitestarPlugin(pluginConfig) {
160
160
  const hint = pluginConfig.types !== false ? pluginConfig.types.routesPath : void 0;
161
161
  litestarMeta = await loadLitestarMeta(resolvedConfig, hint);
162
162
  },
163
- transform(code, id) {
163
+ transform(code, _id) {
164
164
  if (resolvedConfig.command === "serve" && code.includes("__litestar_vite_placeholder__")) {
165
165
  const transformedCode = code.replace(/__litestar_vite_placeholder__/g, viteDevServerUrl);
166
166
  return pluginConfig.transformOnServe(transformedCode, viteDevServerUrl);
@@ -304,7 +304,7 @@ function ensureCommandShouldRunInEnvironment(command, env) {
304
304
  );
305
305
  }
306
306
  }
307
- function pluginVersion() {
307
+ function _pluginVersion() {
308
308
  try {
309
309
  return JSON.parse(fs.readFileSync(path.join(dirname(), "../package.json")).toString())?.version;
310
310
  } catch {
@@ -375,8 +375,8 @@ function resolvePluginConfig(config) {
375
375
  debounce: 300
376
376
  };
377
377
  } else if (typeof resolvedConfig.types === "object" && resolvedConfig.types !== null) {
378
- const userProvidedOpenapi = Object.prototype.hasOwnProperty.call(resolvedConfig.types, "openapiPath");
379
- const userProvidedRoutes = Object.prototype.hasOwnProperty.call(resolvedConfig.types, "routesPath");
378
+ const userProvidedOpenapi = Object.hasOwn(resolvedConfig.types, "openapiPath");
379
+ const userProvidedRoutes = Object.hasOwn(resolvedConfig.types, "routesPath");
380
380
  typesConfig = {
381
381
  enabled: resolvedConfig.types.enabled ?? true,
382
382
  output: resolvedConfig.types.output ?? "src/generated/types",
@@ -409,7 +409,7 @@ function resolvePluginConfig(config) {
409
409
  executor: resolvedConfig.executor ?? pythonDefaults?.executor
410
410
  };
411
411
  }
412
- function resolveBase(config, assetUrl) {
412
+ function resolveBase(_config, assetUrl) {
413
413
  if (process.env.NODE_ENV === "development") {
414
414
  return assetUrl;
415
415
  }
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @module
8
8
  */
9
- export { getCsrfToken, csrfHeaders, csrfFetch, route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, type RouteDefinition, type RoutesMap, } from "litestar-vite-plugin/helpers";
9
+ export { csrfFetch, csrfHeaders, currentRoute, getCsrfToken, getRelativeUrlPath, getRoutes, isCurrentRoute, isRoute, type RouteDefinition, type RoutesMap, route, toRoute, } from "litestar-vite-plugin/helpers";
10
10
  /**
11
11
  * Unwrap page props that may have content nested under "content" key.
12
12
  *
@@ -8,11 +8,11 @@
8
8
  */
9
9
  // Re-export all helpers from the main helpers module
10
10
  // Note: Using package path instead of relative import to ensure proper build output structure
11
- export {
11
+ export { csrfFetch, csrfHeaders, currentRoute,
12
12
  // CSRF utilities
13
- getCsrfToken, csrfHeaders, csrfFetch,
13
+ getCsrfToken, getRelativeUrlPath, getRoutes, isCurrentRoute, isRoute,
14
14
  // Route utilities
15
- route, getRoutes, toRoute, currentRoute, isRoute, isCurrentRoute, getRelativeUrlPath, } from "litestar-vite-plugin/helpers";
15
+ route, toRoute, } from "litestar-vite-plugin/helpers";
16
16
  /**
17
17
  * Unwrap page props that may have content nested under "content" key.
18
18
  *
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "litestar-vite-plugin",
3
- "version": "0.15.0-alpha.3",
3
+ "version": "0.15.0-alpha.4",
4
4
  "type": "module",
5
5
  "description": "Litestar plugin for Vite.",
6
- "keywords": ["litestar", "vite", "vite-plugin"],
6
+ "keywords": [
7
+ "litestar",
8
+ "vite",
9
+ "vite-plugin"
10
+ ],
7
11
  "homepage": "https://github.com/litestar-org/litestar-vite",
8
12
  "repository": {
9
13
  "type": "git",
@@ -40,7 +44,10 @@
40
44
  }
41
45
  },
42
46
  "types": "./dist/js/index.d.ts",
43
- "files": ["dist/js/**/*", "tools/clean.js"],
47
+ "files": [
48
+ "dist/js/**/*",
49
+ "tools/clean.js"
50
+ ],
44
51
  "bin": {
45
52
  "clean-orphaned-assets": "tools/clean.js"
46
53
  },
@@ -56,7 +63,7 @@
56
63
  "test": "vitest --config ./src/js/vitest.config.ts run"
57
64
  },
58
65
  "devDependencies": {
59
- "@biomejs/biome": "1.9.4",
66
+ "@biomejs/biome": "2.0.6",
60
67
  "@types/node": "^22.15.3",
61
68
  "@vitest/coverage-v8": "^3.2.4",
62
69
  "esbuild": "0.25.3",
@@ -66,7 +73,7 @@
66
73
  "vitest": "^3.1.2"
67
74
  },
68
75
  "peerDependencies": {
69
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
76
+ "vite": "^6.0.0 || ^7.0.0"
70
77
  },
71
78
  "engines": {
72
79
  "node": "^20.19.0 || >=22.12.0"
package/tools/clean.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { existsSync, readFileSync, readdirSync, unlinkSync } from "node:fs"
3
+ import { existsSync, readdirSync, readFileSync, unlinkSync } from "node:fs"
4
4
  import { dirname } from "node:path"
5
5
 
6
6
  /*