Build

Build the application for production.

Syntax

$ vela build

This runs vite build with the project’s package manager. The output directory is determined by the SvelteKit adapter configured in vite.config.tsbuild for the default adapters.

Options

  • -t, --target <target> - Which copy of the app to build for. Defaults to production.

Origin of prerendered pages

Prerendering happens with no request to take an origin from, so SvelteKit substitutes a placeholder host and it ends up in every canonical link, og:url and hreflang a prerendered page builds from url.origin.

Vela sets that origin from the domain bound to the target in .vela/project.json, falling back to deploy.domain in velastack.config.ts. Set VELA_ORIGIN to override it. The config reads it as kit.prerender.origin:

sveltekit({
    ...(process.env.VELA_ORIGIN ? { prerender: { origin: process.env.VELA_ORIGIN } } : {})
})

If the target has no domain yet and the build prerendered something, Vela says so rather than shipping the placeholder quietly.

Canonical links and Open Graph image URLs in the templates don’t depend on it: they are built from url in src/lib/site.ts, which has to be set to where the site is deployed. The origin still matters for anything else that reads url.origin.

Database during the build

If the project has a backend, Vela starts PocketBase for the duration of the build and stops it again afterwards. This lets prerendered pages load data from the database without a server running separately. If POCKETBASE_URL is already set in the environment, that database is used instead and nothing is started.

Static builds

Static output is a property of the project, not a build flag. Scaffold with the static template and the project is wired up with @sveltejs/adapter-static and no backend:

$ vela create my-site --template static

An existing project can drop its backend with vela disable backend. See the Static Site Generator page for the limitations that come with it.