Skip to content

svelte

stable

A full Svelte SSR web framework plugin that serves filesystem-routed Svelte components, with support for API routes, middleware, data loaders, and Vite HMR in dev mode.

use plugin svelte::{svelte.app, svelte.render, svelte.build, …}
7 functions Web
/ filter jk navigate Esc clear
Functions (7)
  1. svelte.app Creates a SvelteApp handle by scanning the filesystem routes in dir.
  2. svelte.render Renders a single Svelte component to a full HTML string using SSR.
  3. svelte.build Pre-compiles all Svelte components found under dir and returns a table with compiled, errors, and time_ms.
  4. app.use Registers a middleware function that runs before route handlers.
  5. app.api Registers a Zolo function as a JSON API handler for the given path.
  6. app.load Registers a data loader for a route pattern.
  7. app.serve Starts the HTTP server and blocks indefinitely.

Creates a SvelteApp handle by scanning the filesystem routes in dir.

Creates a SvelteApp handle by scanning the filesystem routes in dir. Optional config accepts port (default 3000), dev (boolean, enables HMR), static (path to public files), lib (path to shared components), and deno_path (custom Deno binary).

use plugin svelte::{svelte}

let app = svelte.app("routes/", #{"port": 8080, "dev": true})
app.serve(app)

Renders a single Svelte component to a full HTML string using SSR.

Renders a single Svelte component to a full HTML string using SSR. Useful for generating static pages or email templates. props is an optional table of component props.

use plugin svelte::{svelte}

let html = svelte.render("components/Card.svelte", #{"title": "Hello", "body": "World"})
print(html)

Pre-compiles all Svelte components found under dir and returns a table with compiled, errors, and time_ms.

Pre-compiles all Svelte components found under dir and returns a table with compiled, errors, and time_ms. Use this for production builds before serving.

use plugin svelte::{svelte}

let result = svelte.build("routes/")
print("compiled {result["compiled"]} components in {result["time_ms"]}ms")

Registers a middleware function that runs before route handlers.

Registers a middleware function that runs before route handlers. With one argument the middleware runs for all routes; with two arguments it only runs for paths starting with path. Middleware receives a request context.

use plugin svelte::{svelte}

let app = svelte.app("routes/")
app.use(app, fn(req) {
    print("request to {req["path"]}")
})

Registers a Zolo function as a JSON API handler for the given path.

Registers a Zolo function as a JSON API handler for the given path. method defaults to "ANY" but can be "GET", "POST", "PUT", "DELETE", etc. Returns the app handle for chaining.

use plugin svelte::{svelte}

let app = svelte.app("routes/")
app.api(app, "/api/hello", fn(req) {
    #{"message": "hello from Zolo"}
}, "GET")
app.serve(app)

Registers a data loader for a route pattern.

Registers a data loader for a route pattern. The loader runs server-side before the Svelte component renders and injects data as props.

use plugin svelte::{svelte}

let app = svelte.app("routes/")
app.load(app, "/blog/:slug", fn(req) {
    #{"title": "Post {req["params"]["slug"]}", "body": "content here"}
})
app.serve(app)

Starts the HTTP server and blocks indefinitely.

Starts the HTTP server and blocks indefinitely. If port is provided it overrides the port from the config. Uses all available CPU cores as worker threads.

use plugin svelte::{svelte}

let app = svelte.app("routes/", #{"port": 3000})
app.serve(app)
enespt-br