litestar-vite 0.12.0__py3-none-any.whl → 0.12.1__py3-none-any.whl
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.
Potentially problematic release.
This version of litestar-vite might be problematic. Click here for more details.
- {litestar_vite-0.12.0.dist-info → litestar_vite-0.12.1.dist-info}/METADATA +1 -1
- litestar_vite-0.12.1.dist-info/RECORD +4 -0
- litestar_vite/__init__.py +0 -8
- litestar_vite/__metadata__.py +0 -18
- litestar_vite/cli.py +0 -320
- litestar_vite/commands.py +0 -139
- litestar_vite/config.py +0 -109
- litestar_vite/inertia/__init__.py +0 -34
- litestar_vite/inertia/_utils.py +0 -63
- litestar_vite/inertia/config.py +0 -29
- litestar_vite/inertia/exception_handler.py +0 -116
- litestar_vite/inertia/middleware.py +0 -51
- litestar_vite/inertia/plugin.py +0 -84
- litestar_vite/inertia/request.py +0 -116
- litestar_vite/inertia/response.py +0 -606
- litestar_vite/inertia/routes.py +0 -54
- litestar_vite/inertia/types.py +0 -39
- litestar_vite/loader.py +0 -284
- litestar_vite/plugin.py +0 -191
- litestar_vite/py.typed +0 -0
- litestar_vite/templates/__init__.py +0 -0
- litestar_vite/templates/index.html.j2 +0 -16
- litestar_vite/templates/main.ts.j2 +0 -1
- litestar_vite/templates/package.json.j2 +0 -11
- litestar_vite/templates/styles.css.j2 +0 -0
- litestar_vite/templates/tsconfig.json.j2 +0 -30
- litestar_vite/templates/vite.config.ts.j2 +0 -37
- litestar_vite-0.12.0.dist-info/RECORD +0 -29
- {litestar_vite-0.12.0.dist-info → litestar_vite-0.12.1.dist-info}/WHEEL +0 -0
- {litestar_vite-0.12.0.dist-info → litestar_vite-0.12.1.dist-info}/licenses/LICENSE +0 -0
litestar_vite/loader.py
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
from functools import cached_property
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from textwrap import dedent
|
|
7
|
-
from typing import TYPE_CHECKING, Any, ClassVar, Mapping, cast
|
|
8
|
-
from urllib.parse import urljoin
|
|
9
|
-
|
|
10
|
-
import markupsafe
|
|
11
|
-
from litestar.exceptions import ImproperlyConfiguredException
|
|
12
|
-
|
|
13
|
-
if TYPE_CHECKING:
|
|
14
|
-
from litestar.connection import Request
|
|
15
|
-
|
|
16
|
-
from litestar_vite.config import ViteConfig
|
|
17
|
-
from litestar_vite.plugin import VitePlugin
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _get_request_from_context(context: Mapping[str, Any]) -> Request[Any, Any, Any]:
|
|
21
|
-
"""Get the request from the template context.
|
|
22
|
-
|
|
23
|
-
Args:
|
|
24
|
-
context: The template context.
|
|
25
|
-
|
|
26
|
-
Returns:
|
|
27
|
-
The request object.
|
|
28
|
-
"""
|
|
29
|
-
return cast("Request[Any, Any, Any]", context["request"])
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def render_hmr_client(context: Mapping[str, Any], /) -> markupsafe.Markup:
|
|
33
|
-
"""Render the HMR client.
|
|
34
|
-
|
|
35
|
-
Args:
|
|
36
|
-
context: The template context.
|
|
37
|
-
|
|
38
|
-
Returns:
|
|
39
|
-
The HMR client.
|
|
40
|
-
"""
|
|
41
|
-
return cast(
|
|
42
|
-
"VitePlugin", _get_request_from_context(context).app.plugins.get("VitePlugin")
|
|
43
|
-
).asset_loader.render_hmr_client()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def render_asset_tag(
|
|
47
|
-
context: Mapping[str, Any], /, path: str | list[str], scripts_attrs: dict[str, str] | None = None
|
|
48
|
-
) -> markupsafe.Markup:
|
|
49
|
-
"""Render an asset tag.
|
|
50
|
-
|
|
51
|
-
Args:
|
|
52
|
-
context: The template context.
|
|
53
|
-
path: The path to the asset.
|
|
54
|
-
scripts_attrs: The attributes for the script tag.
|
|
55
|
-
|
|
56
|
-
Returns:
|
|
57
|
-
The asset tag.
|
|
58
|
-
"""
|
|
59
|
-
return cast(
|
|
60
|
-
"VitePlugin", _get_request_from_context(context).app.plugins.get("VitePlugin")
|
|
61
|
-
).asset_loader.render_asset_tag(path, scripts_attrs)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
class ViteAssetLoader:
|
|
65
|
-
"""Vite manifest loader.
|
|
66
|
-
|
|
67
|
-
Please see: https://vitejs.dev/guide/backend-integration.html
|
|
68
|
-
"""
|
|
69
|
-
|
|
70
|
-
_instance: ClassVar[ViteAssetLoader | None] = None
|
|
71
|
-
|
|
72
|
-
def __init__(self, config: ViteConfig) -> None:
|
|
73
|
-
self._config = config
|
|
74
|
-
self._manifest: dict[str, Any] = {}
|
|
75
|
-
self._manifest_content: str = ""
|
|
76
|
-
self._vite_base_path: str | None = None
|
|
77
|
-
|
|
78
|
-
@classmethod
|
|
79
|
-
def initialize_loader(cls, config: ViteConfig) -> ViteAssetLoader:
|
|
80
|
-
"""Singleton manifest loader."""
|
|
81
|
-
if cls._instance is None:
|
|
82
|
-
cls._instance = cls(config=config)
|
|
83
|
-
cls._instance.parse_manifest()
|
|
84
|
-
return cls._instance
|
|
85
|
-
|
|
86
|
-
@cached_property
|
|
87
|
-
def version_id(self) -> str:
|
|
88
|
-
if self._manifest_content != "":
|
|
89
|
-
return str(hash(self.manifest_content))
|
|
90
|
-
return "1.0"
|
|
91
|
-
|
|
92
|
-
def render_hmr_client(self) -> markupsafe.Markup:
|
|
93
|
-
"""Generate the script tag for the Vite WS client for HMR."""
|
|
94
|
-
return markupsafe.Markup(
|
|
95
|
-
f"{self.generate_react_hmr_tags()}{self.generate_ws_client_tags()}",
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
def render_asset_tag(self, path: str | list[str], scripts_attrs: dict[str, str] | None = None) -> markupsafe.Markup:
|
|
99
|
-
"""Generate all assets include tags for the file in argument."""
|
|
100
|
-
path = [str(p) for p in path] if isinstance(path, list) else [str(path)]
|
|
101
|
-
return markupsafe.Markup(
|
|
102
|
-
"".join([self.generate_asset_tags(p, scripts_attrs=scripts_attrs) for p in path]),
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
def parse_manifest(self) -> None:
|
|
106
|
-
"""Parse the Vite manifest file.
|
|
107
|
-
|
|
108
|
-
The manifest file is a JSON file that maps source files to their corresponding output files.
|
|
109
|
-
Example manifest file structure:
|
|
110
|
-
|
|
111
|
-
.. code-block:: json
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
"main.js": {
|
|
115
|
-
"file": "assets/main.4889e940.js",
|
|
116
|
-
"src": "main.js",
|
|
117
|
-
"isEntry": true,
|
|
118
|
-
"dynamicImports": ["views/foo.js"],
|
|
119
|
-
"css": ["assets/main.b82dbe22.css"],
|
|
120
|
-
"assets": ["assets/asset.0ab0f9cd.png"]
|
|
121
|
-
},
|
|
122
|
-
"views/foo.js": {
|
|
123
|
-
"file": "assets/foo.869aea0d.js",
|
|
124
|
-
"src": "views/foo.js",
|
|
125
|
-
"isDynamicEntry": true,
|
|
126
|
-
"imports": ["_shared.83069a53.js"]
|
|
127
|
-
},
|
|
128
|
-
"_shared.83069a53.js": {
|
|
129
|
-
"file": "assets/shared.83069a53.js"
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
The manifest is parsed and stored in memory for asset resolution during template rendering.
|
|
134
|
-
"""
|
|
135
|
-
if self._config.hot_reload and self._config.dev_mode:
|
|
136
|
-
hot_file_path = Path(
|
|
137
|
-
f"{self._config.bundle_dir}/{self._config.hot_file}",
|
|
138
|
-
)
|
|
139
|
-
if hot_file_path.exists():
|
|
140
|
-
with hot_file_path.open() as hot_file:
|
|
141
|
-
self._vite_base_path = hot_file.read()
|
|
142
|
-
|
|
143
|
-
else:
|
|
144
|
-
manifest_path = Path(f"{self._config.bundle_dir}/{self._config.manifest_name}")
|
|
145
|
-
try:
|
|
146
|
-
if manifest_path.exists():
|
|
147
|
-
with manifest_path.open() as manifest_file:
|
|
148
|
-
self.manifest_content = manifest_file.read()
|
|
149
|
-
self._manifest = json.loads(self.manifest_content)
|
|
150
|
-
else:
|
|
151
|
-
self._manifest = {}
|
|
152
|
-
except Exception as exc:
|
|
153
|
-
msg = "There was an issue reading the Vite manifest file at %s. Did you forget to build your assets?"
|
|
154
|
-
raise RuntimeError(
|
|
155
|
-
msg,
|
|
156
|
-
manifest_path,
|
|
157
|
-
) from exc
|
|
158
|
-
|
|
159
|
-
def generate_ws_client_tags(self) -> str:
|
|
160
|
-
"""Generate the script tag for the Vite WS client for HMR.
|
|
161
|
-
|
|
162
|
-
Only used when hot module reloading is enabled, in production this method returns an empty string.
|
|
163
|
-
|
|
164
|
-
Returns:
|
|
165
|
-
str: The script tag or an empty string.
|
|
166
|
-
"""
|
|
167
|
-
if self._config.hot_reload and self._config.dev_mode:
|
|
168
|
-
return self._script_tag(
|
|
169
|
-
self._vite_server_url("@vite/client"),
|
|
170
|
-
{"type": "module"},
|
|
171
|
-
)
|
|
172
|
-
return ""
|
|
173
|
-
|
|
174
|
-
def generate_react_hmr_tags(self) -> str:
|
|
175
|
-
"""Generate the script tag for the Vite WS client for HMR.
|
|
176
|
-
|
|
177
|
-
Only used when hot module reloading is enabled, in production this method returns an empty string.
|
|
178
|
-
|
|
179
|
-
Returns:
|
|
180
|
-
str: The script tag or an empty string.
|
|
181
|
-
"""
|
|
182
|
-
if self._config.is_react and self._config.hot_reload and self._config.dev_mode:
|
|
183
|
-
return dedent(f"""
|
|
184
|
-
<script type="module">
|
|
185
|
-
import RefreshRuntime from '{self._vite_server_url()}@react-refresh'
|
|
186
|
-
RefreshRuntime.injectIntoGlobalHook(window)
|
|
187
|
-
window.$RefreshReg$ = () => {{}}
|
|
188
|
-
window.$RefreshSig$ = () => (type) => type
|
|
189
|
-
window.__vite_plugin_react_preamble_installed__=true
|
|
190
|
-
</script>
|
|
191
|
-
""")
|
|
192
|
-
return ""
|
|
193
|
-
|
|
194
|
-
def generate_asset_tags(self, path: str | list[str], scripts_attrs: dict[str, str] | None = None) -> str:
|
|
195
|
-
"""Generate all assets include tags for the file in argument.
|
|
196
|
-
|
|
197
|
-
Returns:
|
|
198
|
-
str: All tags to import this asset in your HTML page.
|
|
199
|
-
"""
|
|
200
|
-
if isinstance(path, str):
|
|
201
|
-
path = [path]
|
|
202
|
-
if self._config.hot_reload and self._config.dev_mode:
|
|
203
|
-
return "".join(
|
|
204
|
-
[
|
|
205
|
-
self._style_tag(self._vite_server_url(p))
|
|
206
|
-
if p.endswith(".css")
|
|
207
|
-
else self._script_tag(
|
|
208
|
-
self._vite_server_url(p),
|
|
209
|
-
{"type": "module", "async": "", "defer": ""},
|
|
210
|
-
)
|
|
211
|
-
for p in path
|
|
212
|
-
],
|
|
213
|
-
)
|
|
214
|
-
|
|
215
|
-
if any(p for p in path if p not in self._manifest):
|
|
216
|
-
msg = "Cannot find %s in Vite manifest at %s. Did you forget to build your assets after an update?"
|
|
217
|
-
raise ImproperlyConfiguredException(
|
|
218
|
-
msg,
|
|
219
|
-
path,
|
|
220
|
-
Path(f"{self._config.bundle_dir}/{self._config.manifest_name}"),
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
tags: list[str] = []
|
|
224
|
-
manifest_entry: dict[str, Any] = {}
|
|
225
|
-
manifest_entry.update({p: self._manifest[p] for p in path if p})
|
|
226
|
-
if not scripts_attrs:
|
|
227
|
-
scripts_attrs = {"type": "module", "async": "", "defer": ""}
|
|
228
|
-
for manifest in manifest_entry.values():
|
|
229
|
-
if "css" in manifest:
|
|
230
|
-
tags.extend(
|
|
231
|
-
self._style_tag(urljoin(self._config.asset_url, css_path)) for css_path in manifest.get("css", {})
|
|
232
|
-
)
|
|
233
|
-
# Add dependent "vendor"
|
|
234
|
-
if "imports" in manifest:
|
|
235
|
-
tags.extend(
|
|
236
|
-
self.generate_asset_tags(vendor_path, scripts_attrs=scripts_attrs)
|
|
237
|
-
for vendor_path in manifest.get("imports", {})
|
|
238
|
-
)
|
|
239
|
-
# Add the script by itself
|
|
240
|
-
if manifest.get("file").endswith(".css"):
|
|
241
|
-
tags.append(
|
|
242
|
-
self._style_tag(urljoin(self._config.asset_url, manifest["file"])),
|
|
243
|
-
)
|
|
244
|
-
else:
|
|
245
|
-
tags.append(
|
|
246
|
-
self._script_tag(
|
|
247
|
-
urljoin(self._config.asset_url, manifest["file"]),
|
|
248
|
-
attrs=scripts_attrs,
|
|
249
|
-
),
|
|
250
|
-
)
|
|
251
|
-
return "".join(tags)
|
|
252
|
-
|
|
253
|
-
def _vite_server_url(self, path: str | None = None) -> str:
|
|
254
|
-
"""Generate an URL to and asset served by the Vite development server.
|
|
255
|
-
|
|
256
|
-
Keyword Arguments:
|
|
257
|
-
path: Path to the asset. (default: {None})
|
|
258
|
-
|
|
259
|
-
Returns:
|
|
260
|
-
str: Full URL to the asset.
|
|
261
|
-
"""
|
|
262
|
-
base_path = self._vite_base_path or f"{self._config.protocol}://{self._config.host}:{self._config.port}"
|
|
263
|
-
return urljoin(
|
|
264
|
-
base_path,
|
|
265
|
-
urljoin(self._config.asset_url, path if path is not None else ""),
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
def _script_tag(self, src: str, attrs: dict[str, str] | None = None) -> str:
|
|
269
|
-
"""Generate an HTML script tag."""
|
|
270
|
-
if attrs is None:
|
|
271
|
-
attrs = {}
|
|
272
|
-
attrs_str = " ".join([f'{key}="{value}"' for key, value in attrs.items()])
|
|
273
|
-
return f'<script {attrs_str} src="{src}"></script>'
|
|
274
|
-
|
|
275
|
-
def _style_tag(self, href: str) -> str:
|
|
276
|
-
"""Generate and HTML <link> stylesheet tag for CSS.
|
|
277
|
-
|
|
278
|
-
Args:
|
|
279
|
-
href: CSS file URL.
|
|
280
|
-
|
|
281
|
-
Returns:
|
|
282
|
-
str: CSS link tag.
|
|
283
|
-
"""
|
|
284
|
-
return f'<link rel="stylesheet" href="{href}" />'
|
litestar_vite/plugin.py
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import platform
|
|
5
|
-
import signal
|
|
6
|
-
import subprocess
|
|
7
|
-
import threading
|
|
8
|
-
from contextlib import contextmanager
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from typing import TYPE_CHECKING, Iterator, cast
|
|
11
|
-
|
|
12
|
-
from litestar.cli._utils import console
|
|
13
|
-
from litestar.contrib.jinja import JinjaTemplateEngine
|
|
14
|
-
from litestar.exceptions import ImproperlyConfiguredException
|
|
15
|
-
from litestar.plugins import CLIPlugin, InitPluginProtocol
|
|
16
|
-
from litestar.static_files import create_static_files_router # pyright: ignore[reportUnknownVariableType]
|
|
17
|
-
|
|
18
|
-
if TYPE_CHECKING:
|
|
19
|
-
from click import Group
|
|
20
|
-
from litestar import Litestar
|
|
21
|
-
from litestar.config.app import AppConfig
|
|
22
|
-
|
|
23
|
-
from litestar_vite.config import ViteConfig
|
|
24
|
-
from litestar_vite.loader import ViteAssetLoader
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def set_environment(config: ViteConfig) -> None:
|
|
28
|
-
"""Configure environment for easier integration"""
|
|
29
|
-
os.environ.setdefault("ASSET_URL", config.asset_url)
|
|
30
|
-
os.environ.setdefault("VITE_ALLOW_REMOTE", str(True))
|
|
31
|
-
os.environ.setdefault("VITE_PORT", str(config.port))
|
|
32
|
-
os.environ.setdefault("VITE_HOST", config.host)
|
|
33
|
-
os.environ.setdefault("VITE_PROTOCOL", config.protocol)
|
|
34
|
-
os.environ.setdefault("APP_URL", f"http://localhost:{os.environ.get('LITESTAR_PORT', 8000)}")
|
|
35
|
-
if config.dev_mode:
|
|
36
|
-
os.environ.setdefault("VITE_DEV_MODE", str(config.dev_mode))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class ViteProcess:
|
|
40
|
-
"""Manages the Vite process."""
|
|
41
|
-
|
|
42
|
-
def __init__(self) -> None:
|
|
43
|
-
self.process: subprocess.Popen | None = None # pyright: ignore[reportUnknownMemberType,reportMissingTypeArgument]
|
|
44
|
-
self._lock = threading.Lock()
|
|
45
|
-
|
|
46
|
-
def start(self, command: list[str], cwd: Path | str | None) -> None:
|
|
47
|
-
"""Start the Vite process."""
|
|
48
|
-
|
|
49
|
-
try:
|
|
50
|
-
with self._lock:
|
|
51
|
-
if self.process and self.process.poll() is None: # pyright: ignore[reportUnknownMemberType]
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
console.print(f"Starting Vite process with command: {command}")
|
|
55
|
-
self.process = subprocess.Popen(
|
|
56
|
-
command,
|
|
57
|
-
cwd=cwd,
|
|
58
|
-
shell=platform.system() == "Windows",
|
|
59
|
-
)
|
|
60
|
-
except Exception as e:
|
|
61
|
-
console.print(f"[red]Failed to start Vite process: {e!s}[/]")
|
|
62
|
-
raise
|
|
63
|
-
|
|
64
|
-
def stop(self, timeout: float = 5.0) -> None:
|
|
65
|
-
"""Stop the Vite process."""
|
|
66
|
-
|
|
67
|
-
try:
|
|
68
|
-
with self._lock:
|
|
69
|
-
if self.process and self.process.poll() is None: # pyright: ignore[reportUnknownMemberType]
|
|
70
|
-
# Send SIGTERM to child process
|
|
71
|
-
if hasattr(signal, "SIGTERM"):
|
|
72
|
-
self.process.terminate() # pyright: ignore[reportUnknownMemberType]
|
|
73
|
-
try:
|
|
74
|
-
self.process.wait(timeout=timeout) # pyright: ignore[reportUnknownMemberType]
|
|
75
|
-
except subprocess.TimeoutExpired:
|
|
76
|
-
# Force kill if still alive
|
|
77
|
-
if hasattr(signal, "SIGKILL"):
|
|
78
|
-
self.process.kill() # pyright: ignore[reportUnknownMemberType]
|
|
79
|
-
self.process.wait(timeout=1.0) # pyright: ignore[reportUnknownMemberType]
|
|
80
|
-
console.print("Stopping Vite process")
|
|
81
|
-
except Exception as e:
|
|
82
|
-
console.print(f"[red]Failed to stop Vite process: {e!s}[/]")
|
|
83
|
-
raise
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
class VitePlugin(InitPluginProtocol, CLIPlugin):
|
|
87
|
-
"""Vite plugin."""
|
|
88
|
-
|
|
89
|
-
__slots__ = ("_asset_loader", "_config", "_vite_process")
|
|
90
|
-
|
|
91
|
-
def __init__(self, config: ViteConfig | None = None, asset_loader: ViteAssetLoader | None = None) -> None:
|
|
92
|
-
"""Initialize ``Vite``.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
config: configuration to use for starting Vite. The default configuration will be used if it is not provided.
|
|
96
|
-
asset_loader: an initialized asset loader to use for rendering asset tags.
|
|
97
|
-
"""
|
|
98
|
-
from litestar_vite.config import ViteConfig
|
|
99
|
-
|
|
100
|
-
if config is None:
|
|
101
|
-
config = ViteConfig()
|
|
102
|
-
self._config = config
|
|
103
|
-
self._asset_loader = asset_loader
|
|
104
|
-
self._vite_process = ViteProcess()
|
|
105
|
-
|
|
106
|
-
@property
|
|
107
|
-
def config(self) -> ViteConfig:
|
|
108
|
-
return self._config
|
|
109
|
-
|
|
110
|
-
@property
|
|
111
|
-
def asset_loader(self) -> ViteAssetLoader:
|
|
112
|
-
from litestar_vite.loader import ViteAssetLoader
|
|
113
|
-
|
|
114
|
-
if self._asset_loader is None:
|
|
115
|
-
self._asset_loader = ViteAssetLoader.initialize_loader(config=self._config)
|
|
116
|
-
return self._asset_loader
|
|
117
|
-
|
|
118
|
-
def on_cli_init(self, cli: Group) -> None:
|
|
119
|
-
from litestar_vite.cli import vite_group
|
|
120
|
-
|
|
121
|
-
cli.add_command(vite_group)
|
|
122
|
-
|
|
123
|
-
def on_app_init(self, app_config: AppConfig) -> AppConfig:
|
|
124
|
-
"""Configure application for use with Vite.
|
|
125
|
-
|
|
126
|
-
Args:
|
|
127
|
-
app_config: The :class:`AppConfig <litestar.config.app.AppConfig>` instance.
|
|
128
|
-
"""
|
|
129
|
-
from litestar_vite.loader import render_asset_tag, render_hmr_client
|
|
130
|
-
|
|
131
|
-
if app_config.template_config is None: # pyright: ignore[reportUnknownMemberType]
|
|
132
|
-
msg = "A template configuration is required for Vite."
|
|
133
|
-
raise ImproperlyConfiguredException(msg)
|
|
134
|
-
if not isinstance(app_config.template_config.engine_instance, JinjaTemplateEngine): # pyright: ignore[reportUnknownMemberType]
|
|
135
|
-
msg = "Jinja2 template engine is required for Vite."
|
|
136
|
-
raise ImproperlyConfiguredException(msg)
|
|
137
|
-
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
|
|
138
|
-
key="vite_hmr",
|
|
139
|
-
template_callable=render_hmr_client,
|
|
140
|
-
)
|
|
141
|
-
app_config.template_config.engine_instance.register_template_callable( # pyright: ignore[reportUnknownMemberType]
|
|
142
|
-
key="vite",
|
|
143
|
-
template_callable=render_asset_tag,
|
|
144
|
-
)
|
|
145
|
-
if self._config.set_static_folders:
|
|
146
|
-
static_dirs = [Path(self._config.bundle_dir), Path(self._config.resource_dir)]
|
|
147
|
-
if Path(self._config.public_dir).exists() and self._config.public_dir != self._config.bundle_dir:
|
|
148
|
-
static_dirs.append(Path(self._config.public_dir))
|
|
149
|
-
app_config.route_handlers.append(
|
|
150
|
-
create_static_files_router(
|
|
151
|
-
directories=cast( # type: ignore[arg-type]
|
|
152
|
-
"list[Path]",
|
|
153
|
-
static_dirs if self._config.dev_mode else [Path(self._config.bundle_dir)],
|
|
154
|
-
),
|
|
155
|
-
path=self._config.asset_url,
|
|
156
|
-
name="vite",
|
|
157
|
-
html_mode=False,
|
|
158
|
-
include_in_schema=False,
|
|
159
|
-
opt={"exclude_from_auth": True},
|
|
160
|
-
),
|
|
161
|
-
)
|
|
162
|
-
return app_config
|
|
163
|
-
|
|
164
|
-
@contextmanager
|
|
165
|
-
def server_lifespan(self, app: Litestar) -> Iterator[None]:
|
|
166
|
-
"""Manage Vite server process lifecycle."""
|
|
167
|
-
|
|
168
|
-
if self._config.use_server_lifespan and self._config.dev_mode:
|
|
169
|
-
command_to_run = self._config.run_command if self._config.hot_reload else self._config.build_watch_command
|
|
170
|
-
|
|
171
|
-
if self.config.hot_reload:
|
|
172
|
-
console.rule("[yellow]Starting Vite process with HMR Enabled[/]", align="left")
|
|
173
|
-
else:
|
|
174
|
-
console.rule("[yellow]Starting Vite watch and build process[/]", align="left")
|
|
175
|
-
|
|
176
|
-
if self._config.set_environment:
|
|
177
|
-
set_environment(config=self._config)
|
|
178
|
-
|
|
179
|
-
try:
|
|
180
|
-
self._vite_process.start(command_to_run, self._config.root_dir)
|
|
181
|
-
yield
|
|
182
|
-
finally:
|
|
183
|
-
self._vite_process.stop()
|
|
184
|
-
console.print("[yellow]Vite process stopped.[/]")
|
|
185
|
-
else:
|
|
186
|
-
manifest_path = Path(f"{self._config.bundle_dir}/{self._config.manifest_name}")
|
|
187
|
-
if manifest_path.exists():
|
|
188
|
-
console.rule(f"[yellow]Serving assets using manifest at `{manifest_path!s}`.[/]", align="left")
|
|
189
|
-
else:
|
|
190
|
-
console.rule(f"[yellow]Serving assets without manifest at `{manifest_path!s}`.[/]", align="left")
|
|
191
|
-
yield
|
litestar_vite/py.typed
DELETED
|
File without changes
|
|
File without changes
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
<!--IE compatibility-->
|
|
7
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
8
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
{{ vite_hmr() }}
|
|
13
|
-
{{ vite('resources/main.ts') }}
|
|
14
|
-
</body>
|
|
15
|
-
|
|
16
|
-
</html>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./styles.css"
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"private": true,
|
|
3
|
-
"type": "module",
|
|
4
|
-
"scripts": {
|
|
5
|
-
"dev": "vite",
|
|
6
|
-
"watch": "vite build --watch",
|
|
7
|
-
"build": "vite build{% if enable_ssr %} && vite build --ssr{% endif %}"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {{ dependencies }},
|
|
10
|
-
"devDependencies": {{ dev_dependencies }}
|
|
11
|
-
}
|
|
File without changes
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ES2020",
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"jsx": "preserve",
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"isolatedModules": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"composite": true,
|
|
16
|
-
"allowSyntheticDefaultImports": true,
|
|
17
|
-
"baseUrl": "{{ resource_path }}",
|
|
18
|
-
"paths": {
|
|
19
|
-
"@/*": ["./*"]
|
|
20
|
-
},
|
|
21
|
-
"types": ["vite/client"]
|
|
22
|
-
},
|
|
23
|
-
"include": [
|
|
24
|
-
{% if include_react %}"{{ resource_path }}/**/*.tsx","{{ resource_path }}/**/*.jsx",{% endif %}{% if include_vue %} "{{ resource_path }}/**/*.vue",{% endif %}
|
|
25
|
-
"**/*.d.ts",
|
|
26
|
-
"{{ resource_path }}/**/*.js" ,
|
|
27
|
-
"{{ resource_path }}/**/*.ts" ,
|
|
28
|
-
"vite.config.ts"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
{% if include_vue %}import vue from "@vitejs/plugin-vue";{% endif %}
|
|
3
|
-
{% if include_react %}import react from "@vitejs/plugin-react";{% endif %}
|
|
4
|
-
import litestar from "litestar-vite-plugin";
|
|
5
|
-
|
|
6
|
-
const ASSET_URL = process.env.ASSET_URL || "{{ asset_url }}";
|
|
7
|
-
const VITE_PORT = process.env.VITE_PORT || "5173";
|
|
8
|
-
const VITE_HOST = process.env.VITE_HOST || "localhost";
|
|
9
|
-
export default defineConfig({
|
|
10
|
-
base: `${ASSET_URL}`,
|
|
11
|
-
server: {
|
|
12
|
-
host: "0.0.0.0",
|
|
13
|
-
port: +`${VITE_PORT}`,
|
|
14
|
-
cors: true,
|
|
15
|
-
hmr: {
|
|
16
|
-
host: `${VITE_HOST}`,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
plugins: [
|
|
20
|
-
{% if include_vue %}vue(),{% endif %}
|
|
21
|
-
{% if include_react %}react(),{% endif %}
|
|
22
|
-
litestar({
|
|
23
|
-
input: [
|
|
24
|
-
{% if entry_point %}"{{ entry_point | join('\", \"') }}"{% endif %}
|
|
25
|
-
],
|
|
26
|
-
assetUrl: `${ASSET_URL}`,
|
|
27
|
-
bundleDirectory: "{{ bundle_path }}",
|
|
28
|
-
resourceDirectory: "{{ resource_path }}",
|
|
29
|
-
hotFile: "{{ hot_file }}"
|
|
30
|
-
}),
|
|
31
|
-
],
|
|
32
|
-
resolve: {
|
|
33
|
-
alias: {
|
|
34
|
-
"@": "{{ resource_path }}"
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
litestar_vite/__init__.py,sha256=OioNGhH88mdivQlFz9JlbJV8R6wyjSYE3c8C-RIM4Ls,277
|
|
2
|
-
litestar_vite/__metadata__.py,sha256=_Wo-vNQuj5co9J4FwJAB2rRafbFo8ztTHrXmEPrYrV8,514
|
|
3
|
-
litestar_vite/cli.py,sha256=CBSRohDLU9cDeKMAfSbFiw1x8OE_b15ZlUaxji9Rdw8,10749
|
|
4
|
-
litestar_vite/commands.py,sha256=JTRBvpR_3ddFb2o4-AJSELegw-ZGDsJ_yMaT5FVdp4w,5228
|
|
5
|
-
litestar_vite/config.py,sha256=cZWIwTwNnBYScCty8OxxPaOL8cELx57dm7JQeV8og3Y,4565
|
|
6
|
-
litestar_vite/loader.py,sha256=nrXL2txXoBZEsdLZnysgBYZSreMXQ7ckLuNcu7MqnSM,10277
|
|
7
|
-
litestar_vite/plugin.py,sha256=2ypzvlW5TaOeXTWPa2yHXzkPUf4okRBDl9YHo2qg-cM,8043
|
|
8
|
-
litestar_vite/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
litestar_vite/inertia/__init__.py,sha256=Fab61KXbBnyub2Nx-2AHYv2U6QiYUIrqhEZia_f9xik,863
|
|
10
|
-
litestar_vite/inertia/_utils.py,sha256=ijO9Lgka7ZPIAHkby9szbTGoSg0nDShC2bqWT9cDxi0,1956
|
|
11
|
-
litestar_vite/inertia/config.py,sha256=0Je9SLg0acv0eRvudk3aJLj5k1DjPxULoVOwAfpjnUc,1232
|
|
12
|
-
litestar_vite/inertia/exception_handler.py,sha256=0FiW8jVib0xT453BzMPOeJa7bRwnxkOUdJ91kiFHPIo,5308
|
|
13
|
-
litestar_vite/inertia/middleware.py,sha256=23HfQ8D2wNGXUXt_isuGfZ8AFKrr1d_498qGFLynocs,1650
|
|
14
|
-
litestar_vite/inertia/plugin.py,sha256=f2oFwlEDt9WZ8zt-AqiCIRPlkHIyzLtPYYo8WJZX-tI,3186
|
|
15
|
-
litestar_vite/inertia/request.py,sha256=Ogt_ikauWrsgKafaip7IL1YhbybwjdBAQ0PQS7cImoQ,3848
|
|
16
|
-
litestar_vite/inertia/response.py,sha256=CY-qziEPc9FZ4oXxtgO0Iipg1Hz4x-fiUeLK04Br8kM,23425
|
|
17
|
-
litestar_vite/inertia/routes.py,sha256=QksJm2RUfL-WbuhOieYnPXXWO5GYnPtmsYEm6Ef8Yeo,1782
|
|
18
|
-
litestar_vite/inertia/types.py,sha256=tLp0pm1N__hcWC875khf6wH1nuFlKS9-VjDqgsRkXnw,702
|
|
19
|
-
litestar_vite/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
-
litestar_vite/templates/index.html.j2,sha256=Xue1cTl6piEOZkW3UG68SnW80NeL9PxaOp-Xr23kpr4,322
|
|
21
|
-
litestar_vite/templates/main.ts.j2,sha256=Nzr5m_hXMAjeDL_4yQNP3DMCf7Blh3dwg5m-67GJVbY,22
|
|
22
|
-
litestar_vite/templates/package.json.j2,sha256=0JWgdTuaSZ25EmCltF_zbqDdpxfvCLeYuzBjXrziXNw,299
|
|
23
|
-
litestar_vite/templates/styles.css.j2,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
-
litestar_vite/templates/tsconfig.json.j2,sha256=q1REIuVyXUHCy4Zi2kgTkmrhdT98vyY89k-WTrImOj8,843
|
|
25
|
-
litestar_vite/templates/vite.config.ts.j2,sha256=bF5kOPFafYMkhhV0VkIwetN-_zoVMGVM1jEMX_wKoNc,1037
|
|
26
|
-
litestar_vite-0.12.0.dist-info/METADATA,sha256=0Nv7ZBioTYS6JTE0KzPht82kwBhcBGH7W1cBRB8vgCM,6244
|
|
27
|
-
litestar_vite-0.12.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
28
|
-
litestar_vite-0.12.0.dist-info/licenses/LICENSE,sha256=HeTiEfEgvroUXZe_xAmYHxtTBgw--mbXyZLsWDYabHc,1069
|
|
29
|
-
litestar_vite-0.12.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|