litestar-vite 0.1.7__tar.gz → 0.1.9__tar.gz

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.

Files changed (71) hide show
  1. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/PKG-INFO +17 -9
  2. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/README.md +16 -8
  3. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/htmx/app.py +1 -2
  4. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/react/app.py +1 -2
  5. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/app.py +1 -2
  6. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/cli.py +7 -17
  7. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/commands.py +19 -10
  8. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/config.py +24 -14
  9. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/loader.py +8 -8
  10. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/plugin.py +2 -2
  11. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/index.html.j2 +1 -1
  12. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/package.json.j2 +1 -0
  13. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/vite.config.ts.j2 +11 -2
  14. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/pyproject.toml +1 -1
  15. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/CODEOWNERS +0 -0
  16. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/cd.yaml +0 -0
  17. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/ci.yaml +0 -0
  18. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/docs-preview.yaml +0 -0
  19. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/docs.yaml +0 -0
  20. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/pr-title.yaml +0 -0
  21. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.github/workflows/publish.yaml +0 -0
  22. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.gitignore +0 -0
  23. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/.pre-commit-config.yaml +0 -0
  24. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/CONTRIBUTING.rst +0 -0
  25. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/LICENSE +0 -0
  26. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/Makefile +0 -0
  27. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/Makefile +0 -0
  28. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/conf.py +0 -0
  29. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/contribution-guide.rst +0 -0
  30. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/fix_missing_references.py +0 -0
  31. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/index.rst +0 -0
  32. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/reference/config.rst +0 -0
  33. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/reference/plugin.rst +0 -0
  34. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/usage/index.rst +0 -0
  35. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/docs/usage/placeholder.rst +0 -0
  36. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/__init__.py +0 -0
  37. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/htmx/package.json +0 -0
  38. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/htmx/tsconfig.json +0 -0
  39. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/htmx/vite.config.ts +0 -0
  40. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/__init__.py +0 -0
  41. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/package-lock.json +0 -0
  42. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/package.json +0 -0
  43. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/tsconfig.json +0 -0
  44. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/vite.config.ts +0 -0
  45. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/__init__.py +0 -0
  46. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/controllers.py +0 -0
  47. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/public/.gitkeep +0 -0
  48. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/resources/App.vue +0 -0
  49. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/resources/assets/vue.svg +0 -0
  50. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/resources/main.ts +0 -0
  51. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/resources/styles.css +0 -0
  52. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/examples/vue/web/templates/index.html.j2 +0 -0
  53. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/__init__.py +0 -0
  54. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/__metadata__.py +0 -0
  55. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/py.typed +0 -0
  56. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/template_engine.py +0 -0
  57. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/__init__.py +0 -0
  58. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/htmx/main.css.j2 +0 -0
  59. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/htmx/main.js.j2 +0 -0
  60. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/react/App.tsx.j2 +0 -0
  61. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/react/main.tsx.j2 +0 -0
  62. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/tailwindcss/main.css.j2 +0 -0
  63. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/tailwindcss/postcss.config.ts.j2 +0 -0
  64. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/tailwindcss/tailwind.config.js.j2 +0 -0
  65. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/tsconfig.json.j2 +0 -0
  66. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/vanilla/main.css.j2 +0 -0
  67. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/vue/App.vue.j2 +0 -0
  68. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/litestar_vite/templates/init/vue/main.ts.j2 +0 -0
  69. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/pdm.lock +0 -0
  70. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/tests/__init__.py +0 -0
  71. {litestar_vite-0.1.7 → litestar_vite-0.1.9}/tests/docker-compose.yml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: litestar-vite
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Vite plugin for Litestar
5
5
  Project-URL: Changelog, https://cofin.github.io/litestar-vite/latest/changelog
6
6
  Project-URL: Discord, https://discord.gg/X3FJqy8d2j
@@ -55,7 +55,7 @@ from __future__ import annotations
55
55
 
56
56
  from pathlib import Path
57
57
 
58
- from litestar import Controller, get
58
+ from litestar import Controller, get, Litestar
59
59
  from litestar.response import Template
60
60
  from litestar.status_codes import HTTP_200_OK
61
61
  from litestar_vite import ViteConfig, VitePlugin
@@ -73,9 +73,8 @@ class WebController(Controller):
73
73
  vite = VitePlugin(
74
74
  config=ViteConfig(
75
75
  bundle_dir=Path("./public"),
76
- resources_dir=Path("./resources"),
77
- assets_dir=Path("./resources/assets"),
78
- templates_dir=Path("./templates"),
76
+ resource_dir=Path("./resources"),
77
+ template_dir=Path("./templates"),
79
78
  # Should be False when in production
80
79
  dev_mode=True,
81
80
  hot_reload=True, # Websocket HMR asset reloading is enabled when true.
@@ -83,6 +82,7 @@ vite = VitePlugin(
83
82
  )
84
83
  app = Litestar(plugins=[vite], route_handlers=[WebController])
85
84
 
85
+
86
86
  ```
87
87
 
88
88
  Create a template to serve the application in `./templates/index.html.h2`:
@@ -102,12 +102,16 @@ Create a template to serve the application in `./templates/index.html.h2`:
102
102
 
103
103
  <body class="font-sans leading-none text-gray-700 antialiased">
104
104
  <div id="app"></div>
105
- {{ vite_hmr() }} {{ vite('main.ts') }}
105
+ {{ vite_hmr() }} {{ vite('resources/main.ts') }}
106
106
  </body>
107
107
  </html>
108
108
  ```
109
109
 
110
- Initialize the Vite configuration.
110
+ ### Template initialization (Optional)
111
+
112
+ This is a command to help initialize Vite for your project. This is generally only needed a single time. You may also manually configure Vite and skip this step.
113
+
114
+ to initialize a Vite configuration:
111
115
 
112
116
  ```shell
113
117
  ❯ litestar assets init
@@ -135,10 +139,12 @@ INFO - 2023-12-11 12:33:41,456 - root - commands - Writing tsconfig.json
135
139
  └── assets
136
140
  ```
137
141
 
138
- ### Development
142
+ ### Install Javascript/Typescript Packages
139
143
 
140
144
  Install the packages required for development:
141
145
 
146
+ **Note** This is equivalent to the the `npm install` by default. This command is configurable.
147
+
142
148
  ```shell
143
149
  ❯ litestar assets install
144
150
  Using Litestar app from app:app
@@ -154,6 +160,8 @@ added 25 packages, and audited 26 packages in 1s
154
160
  found 0 vulnerabilities
155
161
  ```
156
162
 
163
+ ### Development
164
+
157
165
  To automatically start and stop the Vite instance with the Litestar application, you can enable the `use_server_lifespan` hooks in the `ViteConfig`.
158
166
 
159
167
  Alternately, to start the development server manually, you can run the following
@@ -173,7 +181,7 @@ vite v5.0.7 building for production...
173
181
 
174
182
  ```
175
183
 
176
- **Note** This is equivalent to the the `npm run dev` command by default.
184
+ **Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build --watch`. This command is configurable.
177
185
 
178
186
  ### Building for Production
179
187
 
@@ -18,7 +18,7 @@ from __future__ import annotations
18
18
 
19
19
  from pathlib import Path
20
20
 
21
- from litestar import Controller, get
21
+ from litestar import Controller, get, Litestar
22
22
  from litestar.response import Template
23
23
  from litestar.status_codes import HTTP_200_OK
24
24
  from litestar_vite import ViteConfig, VitePlugin
@@ -36,9 +36,8 @@ class WebController(Controller):
36
36
  vite = VitePlugin(
37
37
  config=ViteConfig(
38
38
  bundle_dir=Path("./public"),
39
- resources_dir=Path("./resources"),
40
- assets_dir=Path("./resources/assets"),
41
- templates_dir=Path("./templates"),
39
+ resource_dir=Path("./resources"),
40
+ template_dir=Path("./templates"),
42
41
  # Should be False when in production
43
42
  dev_mode=True,
44
43
  hot_reload=True, # Websocket HMR asset reloading is enabled when true.
@@ -46,6 +45,7 @@ vite = VitePlugin(
46
45
  )
47
46
  app = Litestar(plugins=[vite], route_handlers=[WebController])
48
47
 
48
+
49
49
  ```
50
50
 
51
51
  Create a template to serve the application in `./templates/index.html.h2`:
@@ -65,12 +65,16 @@ Create a template to serve the application in `./templates/index.html.h2`:
65
65
 
66
66
  <body class="font-sans leading-none text-gray-700 antialiased">
67
67
  <div id="app"></div>
68
- {{ vite_hmr() }} {{ vite('main.ts') }}
68
+ {{ vite_hmr() }} {{ vite('resources/main.ts') }}
69
69
  </body>
70
70
  </html>
71
71
  ```
72
72
 
73
- Initialize the Vite configuration.
73
+ ### Template initialization (Optional)
74
+
75
+ This is a command to help initialize Vite for your project. This is generally only needed a single time. You may also manually configure Vite and skip this step.
76
+
77
+ to initialize a Vite configuration:
74
78
 
75
79
  ```shell
76
80
  ❯ litestar assets init
@@ -98,10 +102,12 @@ INFO - 2023-12-11 12:33:41,456 - root - commands - Writing tsconfig.json
98
102
  └── assets
99
103
  ```
100
104
 
101
- ### Development
105
+ ### Install Javascript/Typescript Packages
102
106
 
103
107
  Install the packages required for development:
104
108
 
109
+ **Note** This is equivalent to the the `npm install` by default. This command is configurable.
110
+
105
111
  ```shell
106
112
  ❯ litestar assets install
107
113
  Using Litestar app from app:app
@@ -117,6 +123,8 @@ added 25 packages, and audited 26 packages in 1s
117
123
  found 0 vulnerabilities
118
124
  ```
119
125
 
126
+ ### Development
127
+
120
128
  To automatically start and stop the Vite instance with the Litestar application, you can enable the `use_server_lifespan` hooks in the `ViteConfig`.
121
129
 
122
130
  Alternately, to start the development server manually, you can run the following
@@ -136,7 +144,7 @@ vite v5.0.7 building for production...
136
144
 
137
145
  ```
138
146
 
139
- **Note** This is equivalent to the the `npm run dev` command by default.
147
+ **Note** This is equivalent to the the `npm run dev` command when `hot_reload` is enabled. Otherwise it is equivalent to `npm run build --watch`. This command is configurable.
140
148
 
141
149
  ### Building for Production
142
150
 
@@ -12,8 +12,7 @@ vite = VitePlugin(
12
12
  config=ViteConfig(
13
13
  bundle_dir=Path(here / "web" / "public"),
14
14
  resource_dir=Path(here / "web" / "resources"),
15
- assets_dir=Path(here / "web" / "resources" / "assets"),
16
- templates_dir=Path(here / "web" / "templates"),
15
+ template_dir=Path(here / "web" / "templates"),
17
16
  hot_reload=True,
18
17
  ),
19
18
  )
@@ -12,8 +12,7 @@ vite = VitePlugin(
12
12
  config=ViteConfig(
13
13
  bundle_dir=Path(here / "web" / "public"),
14
14
  resource_dir=Path(here / "web" / "resources"),
15
- assets_dir=Path(here / "web" / "resources" / "assets"),
16
- templates_dir=Path(here / "web" / "templates"),
15
+ template_dir=Path(here / "web" / "templates"),
17
16
  hot_reload=True,
18
17
  ),
19
18
  )
@@ -13,8 +13,7 @@ vite = VitePlugin(
13
13
  config=ViteConfig(
14
14
  bundle_dir=Path(here / "web" / "public"),
15
15
  resource_dir=Path(here / "web" / "resources"),
16
- assets_dir=Path(here / "web" / "resources" / "assets"),
17
- templates_dir=Path(here / "web" / "templates"),
16
+ template_dir=Path(here / "web" / "templates"),
18
17
  hot_reload=True,
19
18
  port=3006,
20
19
  ),
@@ -38,13 +38,6 @@ def vite_group() -> None:
38
38
  default=None,
39
39
  required=False,
40
40
  )
41
- @option(
42
- "--asset-path",
43
- type=ClickPath(dir_okay=True, file_okay=False, path_type=Path),
44
- help="The path to your Javascript/Typescript source and associated assets. If this were a standalone Vue or React app, this would point to your `src/` folder.",
45
- default=None,
46
- required=False,
47
- )
48
41
  @option("--asset-url", type=str, help="Base url to serve assets from.", default=None, required=False)
49
42
  @option(
50
43
  "--vite-port",
@@ -78,7 +71,6 @@ def vite_init(
78
71
  vite_port: int | None,
79
72
  enable_ssr: bool | None,
80
73
  asset_url: str | None,
81
- asset_path: Path | None,
82
74
  bundle_path: Path | None,
83
75
  resource_path: Path | None,
84
76
  overwrite: bool,
@@ -103,15 +95,14 @@ def vite_init(
103
95
  config = plugin._config # noqa: SLF001
104
96
 
105
97
  console.rule("[yellow]Initializing Vite[/]", align="left")
106
- resource_path = resource_path or config.resource_dir
107
- asset_path = asset_path or config.assets_dir
108
- bundle_path = bundle_path or config.bundle_dir
98
+ resource_path = Path(resource_path or config.resource_dir)
99
+ bundle_path = Path(bundle_path or config.bundle_dir)
109
100
  enable_ssr = enable_ssr or config.ssr_enabled
110
101
  asset_url = asset_url or config.asset_url
111
102
  vite_port = vite_port or config.port
112
103
  hot_file = Path(bundle_path / config.hot_file)
113
104
  root_path = resource_path.parent
114
- if any(output_path.exists() for output_path in (asset_path, bundle_path, resource_path)) and not any(
105
+ if any(output_path.exists() for output_path in (bundle_path, resource_path)) and not any(
115
106
  [overwrite, no_prompt],
116
107
  ):
117
108
  confirm_overwrite = Confirm.ask(
@@ -120,7 +111,7 @@ def vite_init(
120
111
  if not confirm_overwrite:
121
112
  console.print("Skipping Vite initialization")
122
113
  sys.exit(2)
123
- for output_path in (asset_path, bundle_path, resource_path):
114
+ for output_path in (bundle_path, resource_path):
124
115
  output_path.mkdir(parents=True, exist_ok=True)
125
116
  enable_ssr = (
126
117
  True
@@ -138,7 +129,6 @@ def vite_init(
138
129
  vite_port=vite_port,
139
130
  asset_url=asset_url,
140
131
  resource_path=resource_path,
141
- asset_path=asset_path,
142
132
  bundle_path=bundle_path,
143
133
  hot_file=hot_file,
144
134
  litestar_port=env.port or 8000,
@@ -163,7 +153,7 @@ def vite_install(app: Litestar, verbose: bool) -> None:
163
153
  app.debug = True
164
154
  console.rule("[yellow]Starting Vite package installation process[/]", align="left")
165
155
  plugin = app.plugins.get(VitePlugin)
166
- run_vite(" ".join(plugin._config.install_command)) # noqa: SLF001
156
+ run_vite(" ".join(plugin._config.install_command), app) # noqa: SLF001
167
157
 
168
158
 
169
159
  @vite_group.command( # type: ignore # noqa: PGH003
@@ -184,7 +174,7 @@ def vite_build(app: Litestar, verbose: bool) -> None:
184
174
  app.debug = True
185
175
  console.rule("[yellow]Starting Vite build process[/]", align="left")
186
176
  plugin = app.plugins.get(VitePlugin)
187
- run_vite(" ".join(plugin._config.build_command)) # noqa: SLF001
177
+ run_vite(" ".join(plugin._config.build_command), app) # noqa: SLF001
188
178
 
189
179
 
190
180
  @vite_group.command( # type: ignore # noqa: PGH003
@@ -212,4 +202,4 @@ def vite_serve(app: Litestar, verbose: bool) -> None:
212
202
  command_to_run = (
213
203
  plugin._config.run_command if plugin._config.hot_reload else plugin._config.build_watch_command # noqa: SLF001
214
204
  )
215
- run_vite(" ".join(command_to_run))
205
+ run_vite(" ".join(command_to_run), app)
@@ -4,10 +4,12 @@ import contextlib
4
4
  from pathlib import Path
5
5
  from typing import TYPE_CHECKING, Any, MutableMapping
6
6
 
7
+ from anyio import create_task_group
7
8
  from jinja2 import select_autoescape
8
9
  from litestar.serialization import encode_json
9
10
 
10
11
  if TYPE_CHECKING:
12
+ from anyio.abc import Process
11
13
  from jinja2 import Environment, Template
12
14
  from litestar import Litestar
13
15
 
@@ -40,7 +42,6 @@ def init_vite(
40
42
  app: Litestar,
41
43
  root_path: Path,
42
44
  resource_path: Path,
43
- asset_path: Path,
44
45
  asset_url: str,
45
46
  bundle_path: Path,
46
47
  enable_ssr: bool,
@@ -75,10 +76,9 @@ def init_vite(
75
76
  entry_point=entry_point,
76
77
  enable_ssr=enable_ssr,
77
78
  asset_url=asset_url,
78
- root_path=str(root_path.relative_to(Path.cwd())),
79
+ root_path=str(root_path),
79
80
  resource_path=str(resource_path.relative_to(root_path)),
80
81
  bundle_path=str(bundle_path.relative_to(root_path)),
81
- asset_path=str(asset_path.relative_to(root_path)),
82
82
  hot_file=str(hot_file.relative_to(root_path)),
83
83
  vite_port=str(vite_port),
84
84
  litestar_port=litestar_port,
@@ -97,22 +97,31 @@ def get_template(
97
97
  return environment.get_template(name=name, parent=parent, globals=globals)
98
98
 
99
99
 
100
- def run_vite(command_to_run: str) -> None:
100
+ def run_vite(command_to_run: str, app: Litestar) -> None:
101
101
  """Run Vite in a subprocess."""
102
102
 
103
103
  import anyio
104
104
 
105
105
  with contextlib.suppress(KeyboardInterrupt):
106
- anyio.run(_run_vite, command_to_run)
106
+ anyio.run(_run_vite, command_to_run, app)
107
107
 
108
108
 
109
- async def _run_vite(command_to_run: str) -> None:
109
+ async def _run_vite(command_to_run: str, app: Litestar) -> None:
110
110
  """Run Vite in a subprocess."""
111
111
 
112
112
  from anyio import open_process
113
113
  from anyio.streams.text import TextReceiveStream
114
- from litestar.cli._utils import console
115
114
 
116
- async with await open_process(command_to_run) as vite_process:
117
- async for text in TextReceiveStream(vite_process.stdout): # type: ignore[arg-type]
118
- console.print(text)
115
+ logger = app.get_logger("vite")
116
+
117
+ async def read_stdout(vite_process: Process) -> None:
118
+ async for stdout in TextReceiveStream(vite_process.stdout): # type: ignore[arg-type]
119
+ logger.info(stdout.replace("\n", ""))
120
+
121
+ async def read_stderr(vite_process: Process) -> None:
122
+ async for stdout in TextReceiveStream(vite_process.stderr): # type: ignore[arg-type]
123
+ logger.warning(stdout.replace("\n", ""))
124
+
125
+ async with await open_process(command_to_run) as vite_process, create_task_group() as tg:
126
+ tg.start_soon(read_stdout, vite_process)
127
+ tg.start_soon(read_stderr, vite_process)
@@ -1,8 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import os
3
4
  from dataclasses import dataclass, field
4
5
  from functools import cached_property
5
6
  from inspect import isclass
7
+ from pathlib import Path
6
8
  from typing import TYPE_CHECKING, Generic, TypeVar, cast
7
9
 
8
10
  from litestar.exceptions import ImproperlyConfiguredException
@@ -13,7 +15,6 @@ __all__ = ["ViteConfig", "ViteTemplateConfig"]
13
15
 
14
16
  if TYPE_CHECKING:
15
17
  from collections.abc import Callable
16
- from pathlib import Path
17
18
 
18
19
  from litestar.types import PathType
19
20
 
@@ -31,24 +32,17 @@ class ViteConfig:
31
32
  'plugins' key.
32
33
  """
33
34
 
34
- bundle_dir: Path
35
+ bundle_dir: Path | str = field(default="public")
35
36
  """Location of the compiled assets from Vite.
36
37
 
37
38
  The manifest file will also be found here.
38
39
  """
39
- resource_dir: Path
40
+ resource_dir: Path | str = field(default="resources")
40
41
  """The directory where all typescript/javascript source are written.
41
42
 
42
43
  In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
43
44
  """
44
- assets_dir: Path
45
- """These are the assets that Vite will serve when developing.
46
-
47
- This should include any images, CSS, or other media referenced.
48
-
49
- These will be included in the bundle directory on build.
50
- """
51
- templates_dir: Path
45
+ template_dir: Path | str = field(default="templates")
52
46
  """Location of the Jinja2 template file.
53
47
  """
54
48
  manifest_name: str = ".vite/manifest.json"
@@ -62,9 +56,9 @@ class ViteConfig:
62
56
  """Enable HMR for Vite development server."""
63
57
  ssr_enabled: bool = False
64
58
  """Enable SSR."""
65
- ssr_output_dir: Path | None = None
59
+ ssr_output_dir: Path | str | None = None
66
60
  """SSR Output path"""
67
- root_dir: Path | None = None
61
+ root_dir: Path | str | None = None
68
62
  """The is the base path to your application.
69
63
 
70
64
  In a standalone Vue or React application, this would be equivalent to the ``./src`` directory.
@@ -85,7 +79,7 @@ class ViteConfig:
85
79
  """Default port to use for Vite server."""
86
80
  run_command: list[str] = field(default_factory=lambda: ["npm", "run", "dev"])
87
81
  """Default command to use for running Vite."""
88
- build_watch_command: list[str] = field(default_factory=lambda: ["npm", "run", "build", "--watch"])
82
+ build_watch_command: list[str] = field(default_factory=lambda: ["npm", "run", "watch"])
89
83
  """Default command to use for dev building with Vite."""
90
84
  build_command: list[str] = field(default_factory=lambda: ["npm", "run", "build"])
91
85
  """Default command to use for building with Vite."""
@@ -96,6 +90,22 @@ class ViteConfig:
96
90
  dev_mode: bool = False
97
91
  """When True, Vite will run with HMR or watch build"""
98
92
 
93
+ def __post_init__(self) -> None:
94
+ """Ensure that directory is set if engine is a class."""
95
+ if self.root_dir is not None and isinstance(self.root_dir, str):
96
+ self.root_dir = Path(self.root_dir)
97
+ if isinstance(self.resource_dir, str):
98
+ self.resource_dir = Path(self.resource_dir)
99
+ if isinstance(self.ssr_output_dir, str):
100
+ self.ssr_output_dir = Path(self.ssr_output_dir)
101
+ os.environ.setdefault("LITESTAR_ASSET_URL", self.asset_url)
102
+ os.environ.setdefault("LITESTAR_VITE_ALLOW_REMOTE", str(True))
103
+ os.environ.setdefault("VITE_PORT", str(self.port))
104
+ os.environ.setdefault("VITE_HOST", self.host)
105
+ os.environ.setdefault("VITE_PROTOCOL", self.protocol)
106
+ if self.dev_mode:
107
+ os.environ.setdefault("VITE_DEV_MODE", str(self.dev_mode))
108
+
99
109
 
100
110
  @dataclass
101
111
  class ViteTemplateConfig(Generic[T]):
@@ -64,22 +64,22 @@ class ViteAssetLoader:
64
64
  RuntimeError: if cannot load the file or JSON in file is malformed.
65
65
  """
66
66
  if self._config.hot_reload:
67
- if _hot_file_found := Path(
68
- self._config.bundle_dir / self._config.hot_file,
67
+ if Path(
68
+ f"{self._config.bundle_dir}/{self._config.hot_file}",
69
69
  ).exists():
70
- with Path(self._config.bundle_dir / self._config.hot_file).open() as hot_file:
70
+ with Path(f"{self._config.bundle_dir}/{self._config.manifest_name}").open() as hot_file:
71
71
  self._vite_base_path = hot_file.read()
72
72
 
73
73
  else:
74
- with Path(self._config.bundle_dir / self._config.manifest_name).open() as manifest_file:
74
+ with Path(f"{self._config.bundle_dir}/{self._config.manifest_name}").open() as manifest_file:
75
75
  manifest_content = manifest_file.read()
76
76
  try:
77
77
  self._manifest = json.loads(manifest_content)
78
78
  except Exception as exc: # noqa: BLE001
79
- msg = "Cannot read Vite manifest file at %s"
79
+ msg = "Cannot read Vite manifest file at %s. Did you forget to build your assets?"
80
80
  raise RuntimeError(
81
81
  msg,
82
- Path(self._config.bundle_dir / self._config.manifest_name),
82
+ Path(f"{self._config.bundle_dir}/{self._config.manifest_name}"),
83
83
  ) from exc
84
84
 
85
85
  def generate_ws_client_tags(self) -> str:
@@ -138,11 +138,11 @@ class ViteAssetLoader:
138
138
  )
139
139
 
140
140
  if any(p for p in path if p not in self._manifest):
141
- msg = "Cannot find %s in Vite manifest at %s"
141
+ msg = "Cannot find %s in Vite manifest at %s. Did you forget to build your assets?"
142
142
  raise RuntimeError(
143
143
  msg,
144
144
  path,
145
- Path(self._config.bundle_dir / self._config.manifest_name),
145
+ Path(f"{self._config.bundle_dir}/{self._config.manifest_name}"),
146
146
  )
147
147
 
148
148
  tags: list[str] = []
@@ -45,7 +45,7 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
45
45
  app_config.template_config = ViteTemplateConfig( # type: ignore[assignment]
46
46
  engine=ViteTemplateEngine,
47
47
  config=self._config,
48
- directory=self._config.templates_dir,
48
+ directory=self._config.template_dir,
49
49
  )
50
50
  return app_config
51
51
 
@@ -60,7 +60,7 @@ class VitePlugin(InitPluginProtocol, CLIPlugin):
60
60
 
61
61
  vite_process = multiprocessing.Process(
62
62
  target=run_vite,
63
- args=[command_to_run],
63
+ args=[command_to_run, app],
64
64
  )
65
65
  try:
66
66
  vite_process.start()
@@ -13,6 +13,6 @@
13
13
  <body class="font-sans leading-none text-gray-700 antialiased">
14
14
  <div id="app"></div>
15
15
  {{ vite_hmr() }}
16
- {{ vite('main.ts') }}
16
+ {{ vite('resources/main.ts') }}
17
17
  </body>
18
18
  </html>
@@ -3,6 +3,7 @@
3
3
  "type": "module",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
+ "watch": "vite build --watch",
6
7
  "build": "vite build{% if enable_ssr %} && vite build --ssr{% endif %}"
7
8
  },
8
9
  "dependencies": {{ dependencies }},
@@ -3,8 +3,18 @@ import { defineConfig } from "vite";
3
3
  {% if include_react %}import vue from "@vitejs/plugin-react";{% endif %}
4
4
  import litestar from "litestar-vite-plugin";
5
5
 
6
+ const ASSET_URL =
7
+ process.env.LITESTAR_ASSET_URL || process.env.ASSET_URL || "{{ asset_url }}";
8
+ const VITE_PORT = process.env.VITE_PORT || "5173";
9
+ const VITE_HOST = process.env.VITE_HOST || "localhost";
6
10
  export default defineConfig({
11
+ base: `${ASSET_URL}`,
7
12
  root: "{{ root_path }}",
13
+ server: {
14
+ host: `${VITE_HOST}`,
15
+ port: +`${VITE_PORT}`,
16
+ cors: true,
17
+ },
8
18
  plugins: [
9
19
  {% if include_vue %}vue(),{% endif %}
10
20
  {% if include_react %}react(),{% endif %}
@@ -12,8 +22,7 @@ export default defineConfig({
12
22
  input: [
13
23
  {% if entry_point %}"{{ entry_point | join(', \"') }}"{% endif %}
14
24
  ],
15
- assetUrl: "{{ asset_url }}",
16
- assetDirectory: "{{ asset_path }}",
25
+ assetUrl: `${ASSET_URL}`,
17
26
  bundleDirectory: "{{ bundle_path }}",
18
27
  resourceDirectory: "{{ resource_path }}",
19
28
  hotFile: "{{ hot_file }}"
@@ -33,7 +33,7 @@ license = {text = "MIT"}
33
33
  name = "litestar-vite"
34
34
  readme = "README.md"
35
35
  requires-python = ">=3.8"
36
- version = "0.1.7"
36
+ version = "0.1.9"
37
37
 
38
38
  [project.urls]
39
39
  Changelog = "https://cofin.github.io/litestar-vite/latest/changelog"
File without changes
File without changes
File without changes
File without changes