Dev server (CLI)
wybthon.dev¶
dev
¶
The wyb command: develop, build, and preview Wybthon projects.
A project is a directory with a wybthon.toml (create one with
wyb init). wyb dev builds it in development mode, serves the build,
rebuilds when a source changes, and reloads connected pages over
Server-Sent Events. wyb build writes a production build and
wyb preview serves one.
Use the main function for CLI entry, or call
serve directly to embed the server.
Functions:
| Name | Description |
|---|---|
serve |
Build a project in development mode, serve it, and rebuild on change. |
main |
CLI entry point for |
SSEHandler
¶
Bases: SimpleHTTPRequestHandler
Serves a development build and a /__sse endpoint for reload events.
Class attributes
watchers: wfile objects of connected SSE clients.
root: The build output directory.
app_base: The application's base path; other paths return 404,
and unknown paths under it serve the client shell.
Methods:
| Name | Description |
|---|---|
end_headers |
Append no-cache headers to every response to avoid stale assets. |
do_GET |
Serve the SSE stream or a file from the build. |
translate_path |
Map a request under the app base to the build, falling back to the client shell. |
notify_reload |
Send a |
serve
¶
serve(directory: str | Path = '.', host: str = '127.0.0.1', port: int = 8000, open_browser: bool = False, open_path: str | None = None) -> None
Build a project in development mode, serve it, and rebuild on change.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
The project directory (containing |
'.'
|
host
|
str
|
Bind host. |
'127.0.0.1'
|
port
|
int
|
Preferred port. If busy, the server tries the next 20 ports before failing. |
8000
|
open_browser
|
bool
|
When |
False
|
open_path
|
str | None
|
Path to open instead of the app's base path. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
What's in this module¶
dev is the wyb command. It works on projects: a directory with a
wybthon.toml, created by wyb init. wyb dev builds the project in
development mode, serves the build, rebuilds when a source file changes,
and pushes a reload event over Server-Sent Events at /__sse so open
pages refresh. wyb build writes a production build, which turns dev
mode off, and wyb preview serves one.
| Name | Description |
|---|---|
main |
CLI entry point (wyb init, wyb dev, wyb build, wyb preview). |
serve |
serve(directory=".", host="127.0.0.1", port=8000, open_browser=False, open_path=None): the wyb dev server, callable from Python. |
wyb init my-app
wyb dev --dir my-app --port 8000 --open
wyb build --dir my-app --base /app/
wyb preview --dir my-app/dist
| Command | Flag | Default | Description |
|---|---|---|---|
wyb dev |
--dir |
. |
Project directory (containing wybthon.toml). |
wyb dev |
--host |
127.0.0.1 |
Host interface to bind. |
wyb dev |
--port |
8000 |
Starting port (tries the next 20 on conflict). |
wyb dev |
--open |
off | Open a browser at the app's base path. |
wyb dev |
--open-path |
none | Path to open instead of the base path. |
wyb build |
--dir |
. |
Project directory. |
wyb build |
--out |
<dir>/dist |
Output directory. |
wyb build |
--base |
from wybthon.toml |
Base URL path the app is served from. |
wyb preview |
--dir, --host, --port |
dist, 127.0.0.1, 8000 |
Serve a production build. |
Live reload: wyb dev watches the app directory, public/,
index.html, and wybthon.toml, rebuilds on any change, and
broadcasts reload; the snippet it injects into each served page
reloads it. The static-directory mode of earlier versions, with its
/__manifest endpoint and --mount and --watch flags, is gone; every
served directory is a project. See the
dev server guide.