litestar-vite-plugin 0.18.3 → 0.19.0
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 +37 -142
- package/dist/js/astro.d.ts +4 -4
- package/dist/js/astro.js +7 -3
- package/dist/js/dev-server-index.html +1 -1
- package/dist/js/index.js +12 -6
- package/dist/js/nuxt.d.ts +6 -6
- package/dist/js/nuxt.js +24 -19
- package/dist/js/sveltekit.d.ts +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
# Litestar Vite
|
|
2
2
|
|
|
3
|
-
Litestar Vite connects the Litestar backend to a Vite toolchain. It supports SPA, Template, and
|
|
3
|
+
Litestar Vite connects the Litestar backend to a Vite toolchain. It supports SPA, Template, Inertia, and meta-framework workflows, and it can proxy Vite dev traffic through your ASGI port or run Vite directly.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- One-port dev: proxies Vite HTTP + WS/HMR through Litestar by default; switch to two-port with `VITE_PROXY_MODE=direct`.
|
|
8
|
-
-
|
|
9
|
-
- Production assets: reads Vite manifest from `public/manifest.json` (configurable) and serves under `asset_url`.
|
|
10
|
-
- Type-safe frontends: optional OpenAPI/routes export
|
|
11
|
-
- Inertia support: v2 protocol with session middleware and optional
|
|
8
|
+
- Framework-mode support: use `mode="framework"` (alias `mode="ssr"`) for Astro, Nuxt, and SvelteKit. Litestar proxies everything except your API routes.
|
|
9
|
+
- Production assets: reads the Vite manifest from `public/manifest.json` (configurable) and serves under `asset_url`.
|
|
10
|
+
- Type-safe frontends: optional OpenAPI/routes export plus `@hey-api/openapi-ts` via the Vite plugin.
|
|
11
|
+
- Inertia support: stable v2 protocol with session middleware, optional script-element bootstrap, and optional SSR.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
pip install litestar-vite
|
|
17
|
+
npm install litestar-vite-plugin
|
|
17
18
|
```
|
|
18
19
|
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
19
22
|
```python
|
|
20
23
|
import os
|
|
21
24
|
from pathlib import Path
|
|
22
25
|
from litestar import Litestar
|
|
23
|
-
from litestar_vite import
|
|
26
|
+
from litestar_vite import PathConfig, ViteConfig, VitePlugin
|
|
24
27
|
|
|
25
28
|
DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
|
|
26
29
|
|
|
@@ -33,155 +36,47 @@ app = Litestar(
|
|
|
33
36
|
```
|
|
34
37
|
|
|
35
38
|
```bash
|
|
36
|
-
litestar
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Scaffold a frontend: `litestar assets init --template vue` (or `react`, `svelte`, `htmx`, `react-inertia`, `vue-inertia`, `angular`, `astro`, `nuxt`, `sveltekit`).
|
|
40
|
-
|
|
41
|
-
## Development
|
|
42
|
-
|
|
43
|
-
To contribute or run the development project:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# Install all dependencies and build packages
|
|
47
|
-
make install && make build
|
|
48
|
-
|
|
49
|
-
# Install frontend dependencies for an example
|
|
50
|
-
uv run litestar --app-dir examples/vue-inertia assets install
|
|
51
|
-
|
|
52
|
-
# Run the development server
|
|
53
|
-
uv run litestar --app-dir examples/vue-inertia run
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Replace `vue-inertia` with any other example: `vue`, `react`, `svelte`, `react-inertia`, `htmx`, `angular`, `astro`, `nuxt`, or `sveltekit`.
|
|
57
|
-
|
|
58
|
-
## Template / HTMX
|
|
59
|
-
|
|
60
|
-
```python
|
|
61
|
-
from pathlib import Path
|
|
62
|
-
from litestar import Litestar
|
|
63
|
-
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
64
|
-
from litestar.template import TemplateConfig
|
|
65
|
-
from litestar_vite import VitePlugin, ViteConfig, PathConfig
|
|
66
|
-
|
|
67
|
-
here = Path(__file__).parent
|
|
68
|
-
|
|
69
|
-
app = Litestar(
|
|
70
|
-
template_config=TemplateConfig(directory=here / "templates", engine=JinjaTemplateEngine),
|
|
71
|
-
plugins=[VitePlugin(config=ViteConfig(
|
|
72
|
-
dev_mode=True,
|
|
73
|
-
paths=PathConfig(root=here),
|
|
74
|
-
))],
|
|
75
|
-
)
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Inertia (v2)
|
|
79
|
-
|
|
80
|
-
Requires session middleware (32-char secret).
|
|
81
|
-
|
|
82
|
-
```python
|
|
83
|
-
import os
|
|
84
|
-
from pathlib import Path
|
|
85
|
-
from litestar import Litestar
|
|
86
|
-
from litestar.middleware.session.client_side import CookieBackendConfig
|
|
87
|
-
from litestar_vite import VitePlugin, ViteConfig, PathConfig
|
|
88
|
-
from litestar_vite.inertia import InertiaConfig
|
|
89
|
-
|
|
90
|
-
here = Path(__file__).parent
|
|
91
|
-
SECRET_KEY = os.environ.get("SECRET_KEY", "development-only-secret-32-chars")
|
|
92
|
-
session = CookieBackendConfig(secret=SECRET_KEY.encode("utf-8"))
|
|
93
|
-
|
|
94
|
-
app = Litestar(
|
|
95
|
-
middleware=[session.middleware],
|
|
96
|
-
plugins=[VitePlugin(config=ViteConfig(
|
|
97
|
-
dev_mode=True,
|
|
98
|
-
paths=PathConfig(root=here),
|
|
99
|
-
inertia=InertiaConfig(root_template="index.html"),
|
|
100
|
-
))],
|
|
101
|
-
)
|
|
39
|
+
litestar assets init --template vue
|
|
40
|
+
litestar assets install
|
|
41
|
+
litestar run --reload
|
|
102
42
|
```
|
|
103
43
|
|
|
104
|
-
##
|
|
105
|
-
|
|
106
|
-
Use `mode="ssr"` (or `mode="framework"`) to proxy non-API routes to the framework's dev server:
|
|
107
|
-
|
|
108
|
-
```python
|
|
109
|
-
import os
|
|
110
|
-
from pathlib import Path
|
|
111
|
-
from litestar import Litestar
|
|
112
|
-
from litestar_vite import VitePlugin, ViteConfig, PathConfig
|
|
113
|
-
|
|
114
|
-
here = Path(__file__).parent
|
|
115
|
-
DEV_MODE = os.getenv("VITE_DEV_MODE", "true").lower() in ("true", "1", "yes")
|
|
116
|
-
|
|
117
|
-
app = Litestar(
|
|
118
|
-
plugins=[
|
|
119
|
-
VitePlugin(config=ViteConfig(
|
|
120
|
-
mode="ssr",
|
|
121
|
-
dev_mode=DEV_MODE,
|
|
122
|
-
paths=PathConfig(root=here),
|
|
123
|
-
))
|
|
124
|
-
],
|
|
125
|
-
)
|
|
126
|
-
```
|
|
44
|
+
## Documentation
|
|
127
45
|
|
|
128
|
-
|
|
46
|
+
- **[Usage Guide](https://litestar-org.github.io/litestar-vite/latest/usage/)**: Core concepts, configuration, and type generation.
|
|
47
|
+
- **[Inertia](https://litestar-org.github.io/litestar-vite/latest/inertia/)**: Fullstack protocols and SSR.
|
|
48
|
+
- **[Frameworks](https://litestar-org.github.io/litestar-vite/latest/frameworks/)**: Guides for React, Vue, Svelte, Angular, Astro, and Nuxt.
|
|
49
|
+
- **[Reference](https://litestar-org.github.io/litestar-vite/latest/reference/)**: API and CLI documentation.
|
|
129
50
|
|
|
130
|
-
|
|
131
|
-
|------|-------|----------|
|
|
132
|
-
| `vite` | - | SPAs - proxies Vite assets only (default) |
|
|
133
|
-
| `direct` | - | Two-port dev - expose Vite port directly |
|
|
134
|
-
| `proxy` | `ssr` | Meta-frameworks - proxies everything except API routes |
|
|
51
|
+
For a full list of changes, see the [Changelog](https://litestar-org.github.io/litestar-vite/latest/changelog.html).
|
|
135
52
|
|
|
136
|
-
|
|
53
|
+
## Common Commands
|
|
137
54
|
|
|
138
|
-
|
|
55
|
+
- `litestar assets init --template <name>`: scaffold a frontend or framework app
|
|
56
|
+
- `litestar assets install`: install frontend dependencies with the configured executor
|
|
57
|
+
- `litestar assets build`: build production assets
|
|
58
|
+
- `litestar assets serve`: run the frontend toolchain directly
|
|
59
|
+
- `litestar assets generate-types`: export OpenAPI, routes, and Inertia page-prop metadata
|
|
60
|
+
- `litestar assets doctor`: inspect and optionally repair config drift
|
|
139
61
|
|
|
140
|
-
|
|
141
|
-
litestar --app-dir examples/astro assets install
|
|
142
|
-
litestar --app-dir examples/astro assets build
|
|
143
|
-
VITE_DEV_MODE=false litestar --app-dir examples/astro run
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Nuxt/SvelteKit (SSR):** These run their own Node servers. Deploy as two services:
|
|
62
|
+
## Development
|
|
147
63
|
|
|
148
64
|
```bash
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
litestar --app-dir examples/nuxt assets serve
|
|
152
|
-
|
|
153
|
-
# Terminal 2: Litestar API
|
|
154
|
-
VITE_DEV_MODE=false litestar --app-dir examples/nuxt run --port 8001
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Type generation
|
|
158
|
-
|
|
159
|
-
```python
|
|
160
|
-
VitePlugin(config=ViteConfig(types=True)) # enable exports
|
|
161
|
-
```
|
|
65
|
+
# Install Python, docs, and JS dependencies; build package artifacts
|
|
66
|
+
make install && make build
|
|
162
67
|
|
|
163
|
-
|
|
164
|
-
litestar
|
|
68
|
+
# Run an example app
|
|
69
|
+
uv run litestar --app-dir examples/vue-inertia assets install
|
|
70
|
+
uv run litestar --app-dir examples/vue-inertia run
|
|
165
71
|
```
|
|
166
72
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
- `litestar assets doctor` — diagnose/fix config
|
|
170
|
-
- `litestar assets init --template react|vue|svelte|...` — scaffold frontend
|
|
171
|
-
- `litestar assets build` / `serve` — build or watch
|
|
172
|
-
- `litestar assets deploy --storage gcs://bucket/assets` — upload via fsspec
|
|
173
|
-
- `litestar assets generate-types` — OpenAPI + routes → TS types
|
|
174
|
-
- `litestar assets install` — install frontend deps with the configured executor
|
|
175
|
-
|
|
176
|
-
### Doctor command highlights
|
|
73
|
+
Replace `vue-inertia` with any other example app: `vue`, `react`, `svelte`, `react-inertia`, `htmx`, `angular`, `astro`, `nuxt`, or `sveltekit`.
|
|
177
74
|
|
|
178
|
-
-
|
|
179
|
-
- Flags missing hot file (dev proxy), missing manifest (prod), type-gen exports, env/config mismatches, and plugin install issues.
|
|
180
|
-
- `--fix` can rewrite simple vite.config values (assetUrl, bundleDir, hotFile, type paths) after creating a backup.
|
|
75
|
+
For Inertia script-element bootstrap, enable `InertiaConfig(use_script_element=True)` on the Python side and keep `createInertiaApp({ defaults: { future: { useScriptElementForInitialPage: true } } })` aligned in the browser entry and SSR entry when `ssr=True` is enabled.
|
|
181
76
|
|
|
182
77
|
## Links
|
|
183
78
|
|
|
184
|
-
- Docs: <https://litestar-org.github.io/litestar-vite/>
|
|
185
|
-
- Examples: `examples/` (
|
|
186
|
-
- Real-world example: [litestar-fullstack](https://github.com/litestar-org/litestar-fullstack)
|
|
79
|
+
- Docs: <https://litestar-org.github.io/litestar-vite/latest/>
|
|
80
|
+
- Examples: `examples/` (React, Vue, Svelte, HTMX, Inertia, Astro, Nuxt, SvelteKit, Angular)
|
|
81
|
+
- Real-world example: [litestar-fullstack](https://github.com/litestar-org/litestar-fullstack)
|
|
187
82
|
- Issues: <https://github.com/litestar-org/litestar-vite/issues/>
|
package/dist/js/astro.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Astro integration for Litestar-Vite.
|
|
2
|
+
* Astro 5 integration for Litestar-Vite.
|
|
3
3
|
*
|
|
4
4
|
* This integration enables seamless development with Astro as the frontend framework
|
|
5
5
|
* and Litestar as the API backend. It provides:
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* export default defineConfig({
|
|
17
17
|
* integrations: [
|
|
18
18
|
* litestar({
|
|
19
|
-
* apiProxy: 'http://
|
|
19
|
+
* apiProxy: 'http://127.0.0.1:8000',
|
|
20
20
|
* types: true,
|
|
21
21
|
* }),
|
|
22
22
|
* ],
|
|
@@ -178,7 +178,7 @@ export interface LitestarAstroConfig {
|
|
|
178
178
|
/**
|
|
179
179
|
* URL of the Litestar API backend for proxying requests during development.
|
|
180
180
|
*
|
|
181
|
-
* @example 'http://
|
|
181
|
+
* @example 'http://127.0.0.1:8000'
|
|
182
182
|
* @default 'http://localhost:8000'
|
|
183
183
|
*/
|
|
184
184
|
apiProxy?: string;
|
|
@@ -224,7 +224,7 @@ export interface LitestarAstroConfig {
|
|
|
224
224
|
* export default defineConfig({
|
|
225
225
|
* integrations: [
|
|
226
226
|
* litestar({
|
|
227
|
-
* apiProxy: 'http://
|
|
227
|
+
* apiProxy: 'http://127.0.0.1:8000',
|
|
228
228
|
* apiPrefix: '/api',
|
|
229
229
|
* types: {
|
|
230
230
|
* enabled: true,
|
package/dist/js/astro.js
CHANGED
|
@@ -187,7 +187,9 @@ function litestarAstro(userConfig = {}) {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
updateConfig(configUpdate);
|
|
190
|
-
|
|
190
|
+
if (config.verbose) {
|
|
191
|
+
logger.info(`Litestar integration configured - proxying ${config.apiPrefix}/* to ${config.apiProxy}`);
|
|
192
|
+
}
|
|
191
193
|
},
|
|
192
194
|
"astro:server:setup": ({ server, logger }) => {
|
|
193
195
|
if (config.verbose) {
|
|
@@ -216,8 +218,10 @@ function litestarAstro(userConfig = {}) {
|
|
|
216
218
|
}
|
|
217
219
|
},
|
|
218
220
|
"astro:build:start": ({ logger }) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
if (config.verbose) {
|
|
222
|
+
logger.info("Building with Litestar integration");
|
|
223
|
+
logger.info(` Make sure your Litestar backend is accessible at: ${config.apiProxy}`);
|
|
224
|
+
}
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
};
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
</div>
|
|
59
59
|
|
|
60
60
|
<!-- Vite Logo -->
|
|
61
|
-
<a href="https://
|
|
61
|
+
<a href="https://vite.dev" target="_blank" class="group transition-transform hover:scale-110 duration-300 relative">
|
|
62
62
|
<div class="absolute inset-0 bg-purple-500/20 blur-xl rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-300"></div>
|
|
63
63
|
<svg viewBox="0 0 410 404" class="relative h-16 w-auto drop-shadow-lg" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
64
64
|
<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
|
package/dist/js/index.js
CHANGED
|
@@ -113,6 +113,8 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
113
113
|
})
|
|
114
114
|
);
|
|
115
115
|
};
|
|
116
|
+
const explicitServerOrigin = typeof userConfig.server?.origin === "string" && userConfig.server.origin.length > 0 ? userConfig.server.origin : void 0;
|
|
117
|
+
const shouldForceDirectServerOrigin = explicitServerOrigin !== void 0 || pythonDefaults?.proxyMode === "direct";
|
|
116
118
|
const devBase = pluginConfig.assetUrl.startsWith("/") ? pluginConfig.assetUrl : pluginConfig.assetUrl.replace(/\/+$/, "");
|
|
117
119
|
ensureCommandShouldRunInEnvironment(command, env, mode);
|
|
118
120
|
return {
|
|
@@ -129,7 +131,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
129
131
|
assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0
|
|
130
132
|
},
|
|
131
133
|
server: {
|
|
132
|
-
origin:
|
|
134
|
+
origin: shouldForceDirectServerOrigin ? explicitServerOrigin ?? "__litestar_vite_placeholder__" : void 0,
|
|
133
135
|
// Auto-configure HMR to use a path that routes through Litestar proxy
|
|
134
136
|
// Note: Vite automatically prepends `base` to `hmr.path`, so we just use "vite-hmr"
|
|
135
137
|
// Result: base="/static/" + path="vite-hmr" = "/static/vite-hmr"
|
|
@@ -239,7 +241,8 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
239
241
|
const address = server.httpServer?.address();
|
|
240
242
|
const isAddressInfo = (x) => typeof x === "object";
|
|
241
243
|
if (isAddressInfo(address)) {
|
|
242
|
-
|
|
244
|
+
const explicitServerOrigin = typeof userConfig.server?.origin === "string" && userConfig.server.origin.length > 0 ? userConfig.server.origin : void 0;
|
|
245
|
+
viteDevServerUrl = explicitServerOrigin ? explicitServerOrigin : resolveDevServerUrl(address, server.config, userConfig);
|
|
243
246
|
fs.mkdirSync(path.dirname(pluginConfig.hotFile), { recursive: true });
|
|
244
247
|
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
245
248
|
setTimeout(async () => {
|
|
@@ -515,7 +518,7 @@ function formatMissingConfigWarning() {
|
|
|
515
518
|
`${y("\u2502")} ${d(" types: false,")} ${y("\u2502")}`,
|
|
516
519
|
`${y("\u2502")} ${d("})")} ${y("\u2502")}`,
|
|
517
520
|
`${y("\u2502")} ${y("\u2502")}`,
|
|
518
|
-
`${y("\u2502")} Docs: ${c("https://
|
|
521
|
+
`${y("\u2502")} Docs: ${c("https://litestar-org.github.io/litestar-vite/latest/usage/vite/")} ${y("\u2502")}`,
|
|
519
522
|
`${y("\u2502")} ${y("\u2502")}`,
|
|
520
523
|
y("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F"),
|
|
521
524
|
"",
|
|
@@ -706,7 +709,7 @@ function validateAgainstPythonDefaults(resolved, pythonDefaults, userConfig) {
|
|
|
706
709
|
colors.yellow("[litestar-vite] Configuration mismatch detected:\n") + warnings.map((w) => ` ${colors.dim("\u2022")} ${w}`).join("\n") + `
|
|
707
710
|
|
|
708
711
|
${colors.dim("Precedence: vite.config.ts > .litestar.json > defaults")}
|
|
709
|
-
` + colors.dim("See: https://
|
|
712
|
+
` + colors.dim("See: https://litestar-org.github.io/litestar-vite/latest/usage/vite/\n")
|
|
710
713
|
);
|
|
711
714
|
}
|
|
712
715
|
}
|
|
@@ -786,12 +789,15 @@ function resolveDevServerUrl(address, config, userConfig) {
|
|
|
786
789
|
const serverProtocol = config.server.https ? "https" : "http";
|
|
787
790
|
const protocol = clientProtocol ?? serverProtocol;
|
|
788
791
|
const configHmrHost = typeof config.server.hmr === "object" ? config.server.hmr.host : null;
|
|
792
|
+
const userHost = typeof userConfig.server?.host === "string" ? userConfig.server.host : null;
|
|
789
793
|
const configHost = typeof config.server.host === "string" ? config.server.host : null;
|
|
790
|
-
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? "
|
|
794
|
+
const remoteHost = process.env.VITE_ALLOW_REMOTE && !userConfig.server?.host ? isIpv6(address) ? "[::1]" : "127.0.0.1" : null;
|
|
791
795
|
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address;
|
|
792
|
-
let host = configHmrHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
796
|
+
let host = configHmrHost ?? userHost ?? remoteHost ?? configHost ?? serverAddress;
|
|
793
797
|
if (host === "0.0.0.0") {
|
|
794
798
|
host = "127.0.0.1";
|
|
799
|
+
} else if (host === "::" || host === "[::]") {
|
|
800
|
+
host = "[::1]";
|
|
795
801
|
}
|
|
796
802
|
const configHmrClientPort = typeof config.server.hmr === "object" ? config.server.hmr.clientPort : null;
|
|
797
803
|
const port = configHmrClientPort ?? address.port;
|
package/dist/js/nuxt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Nuxt module for Litestar-Vite.
|
|
2
|
+
* Nuxt 4 module for Litestar-Vite.
|
|
3
3
|
*
|
|
4
|
-
* This module provides seamless integration between Nuxt
|
|
4
|
+
* This module provides seamless integration between Nuxt 4 and a Litestar backend.
|
|
5
5
|
* It enables:
|
|
6
6
|
* - API proxy configuration for dev server
|
|
7
7
|
* - Type generation integration (shares @hey-api/openapi-ts output)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* export default defineNuxtConfig({
|
|
14
14
|
* modules: ['litestar-vite-plugin/nuxt'],
|
|
15
15
|
* litestar: {
|
|
16
|
-
* apiProxy: 'http://
|
|
16
|
+
* apiProxy: 'http://127.0.0.1:8000',
|
|
17
17
|
* apiPrefix: '/api',
|
|
18
18
|
* types: true,
|
|
19
19
|
* },
|
|
@@ -114,7 +114,7 @@ export interface LitestarNuxtConfig {
|
|
|
114
114
|
/**
|
|
115
115
|
* URL of the Litestar API backend for proxying requests during development.
|
|
116
116
|
*
|
|
117
|
-
* @example 'http://
|
|
117
|
+
* @example 'http://127.0.0.1:8000'
|
|
118
118
|
* @default 'http://localhost:8000'
|
|
119
119
|
*/
|
|
120
120
|
apiProxy?: string;
|
|
@@ -160,7 +160,7 @@ export interface LitestarNuxtConfig {
|
|
|
160
160
|
* export default defineNuxtConfig({
|
|
161
161
|
* modules: ['litestar-vite-plugin/nuxt'],
|
|
162
162
|
* litestar: {
|
|
163
|
-
* apiProxy: 'http://
|
|
163
|
+
* apiProxy: 'http://127.0.0.1:8000',
|
|
164
164
|
* apiPrefix: '/api',
|
|
165
165
|
* types: {
|
|
166
166
|
* enabled: true,
|
|
@@ -172,7 +172,7 @@ export interface LitestarNuxtConfig {
|
|
|
172
172
|
*
|
|
173
173
|
* @example Using generated types in a composable
|
|
174
174
|
* ```typescript
|
|
175
|
-
* // composables/useApi.ts
|
|
175
|
+
* // app/composables/useApi.ts
|
|
176
176
|
* import type { User } from '~/generated/api/types.gen';
|
|
177
177
|
* import { route } from '~/generated/routes';
|
|
178
178
|
*
|
package/dist/js/nuxt.js
CHANGED
|
@@ -168,21 +168,23 @@ function createProxyPlugin(config) {
|
|
|
168
168
|
console.log(colors.cyan("[litestar-nuxt]"), colors.dim(`HMR Hotfile written: ${hmrHotFile} -> ${hmrUrl}`));
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
171
|
+
if (config.verbose) {
|
|
172
|
+
server.httpServer?.once("listening", () => {
|
|
173
|
+
setTimeout(() => {
|
|
174
|
+
console.log("");
|
|
175
|
+
console.log(` ${colors.cyan("[litestar-nuxt]")} ${colors.green("Integration active")}`);
|
|
176
|
+
console.log(` ${colors.dim("\u251C\u2500")} API Proxy: ${colors.yellow(config.apiProxy)}`);
|
|
177
|
+
console.log(` ${colors.dim("\u251C\u2500")} API Prefix: ${colors.yellow(config.apiPrefix)}`);
|
|
178
|
+
console.log(` ${colors.dim("\u251C\u2500")} HMR Port: ${colors.yellow(hmrPort)}`);
|
|
179
|
+
if (config.types !== false && config.types.enabled) {
|
|
180
|
+
console.log(` ${colors.dim("\u2514\u2500")} Types Output: ${colors.yellow(config.types.output)}`);
|
|
181
|
+
} else {
|
|
182
|
+
console.log(` ${colors.dim("\u2514\u2500")} Types: ${colors.dim("disabled")}`);
|
|
183
|
+
}
|
|
184
|
+
console.log("");
|
|
185
|
+
}, 100);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
186
188
|
}
|
|
187
189
|
};
|
|
188
190
|
}
|
|
@@ -232,7 +234,7 @@ function litestarNuxtModule(userOptions, nuxt) {
|
|
|
232
234
|
console.log(JSON.stringify(nuxt.options.nitro.devProxy, null, 2));
|
|
233
235
|
}
|
|
234
236
|
if (config.hotFile && config.devPort) {
|
|
235
|
-
const rawHost = process.env.NUXT_HOST || process.env.HOST || "
|
|
237
|
+
const rawHost = process.env.NUXT_HOST || process.env.HOST || "127.0.0.1";
|
|
236
238
|
const host = normalizeHost(rawHost);
|
|
237
239
|
const url = `http://${host}:${config.devPort}`;
|
|
238
240
|
fs.mkdirSync(path.dirname(config.hotFile), { recursive: true });
|
|
@@ -245,8 +247,9 @@ function litestarNuxtModule(userOptions, nuxt) {
|
|
|
245
247
|
nuxt.hook("listen", (_server, listener) => {
|
|
246
248
|
const info = listener;
|
|
247
249
|
if (info && typeof info.port === "number") {
|
|
248
|
-
const host = normalizeHost(info.host || "
|
|
250
|
+
const host = normalizeHost(info.host || "127.0.0.1");
|
|
249
251
|
const url = `http://${host}:${info.port}`;
|
|
252
|
+
fs.mkdirSync(path.dirname(config.hotFile), { recursive: true });
|
|
250
253
|
fs.writeFileSync(config.hotFile, url);
|
|
251
254
|
if (config.verbose) {
|
|
252
255
|
console.log(colors.cyan("[litestar-nuxt]"), colors.dim(`Hotfile updated via listen hook: ${url}`));
|
|
@@ -254,13 +257,15 @@ function litestarNuxtModule(userOptions, nuxt) {
|
|
|
254
257
|
}
|
|
255
258
|
});
|
|
256
259
|
}
|
|
257
|
-
|
|
260
|
+
if (config.verbose) {
|
|
261
|
+
console.log(colors.cyan("[litestar-nuxt]"), "Module initialized");
|
|
262
|
+
}
|
|
258
263
|
}
|
|
259
264
|
litestarNuxtModule.meta = {
|
|
260
265
|
name: "litestar-vite",
|
|
261
266
|
configKey: "litestar",
|
|
262
267
|
compatibility: {
|
|
263
|
-
nuxt: ">=
|
|
268
|
+
nuxt: ">=4.0.0"
|
|
264
269
|
}
|
|
265
270
|
};
|
|
266
271
|
litestarNuxtModule.getOptions = () => ({
|
package/dist/js/sveltekit.d.ts
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
*
|
|
28
28
|
* @module
|
|
29
29
|
*/
|
|
30
|
-
import type { Plugin } from "vite";
|
|
31
30
|
/**
|
|
32
31
|
* Configuration for TypeScript type generation in SvelteKit.
|
|
33
32
|
*/
|
|
@@ -200,5 +199,5 @@ export interface LitestarSvelteKitConfig {
|
|
|
200
199
|
* };
|
|
201
200
|
* ```
|
|
202
201
|
*/
|
|
203
|
-
export declare function litestarSvelteKit(userConfig?: LitestarSvelteKitConfig):
|
|
202
|
+
export declare function litestarSvelteKit(userConfig?: LitestarSvelteKitConfig): any[];
|
|
204
203
|
export default litestarSvelteKit;
|