Building Your App
Edit this page on GitHubBuilding a SvelteKit consists of two stages. First the production build is run. This will create a client and a server build which are later consumed by the corresponding environments. Prerendering is executed at this stage, if enabled. The second stage is to adapt the output to your deployment target using adapters (more on that in the adapters docs).
During the buildpermalink
SvelteKit will load your +page/layout(.server).js
files (and all files they import) for analysis during the build. This could lead to code eagerly running which you want to avoid at that stage. Wrap the code in question with building
from $app/environment
:
ts
import {building } from '$app/environment';import {setupMyDatabase } from '$lib/server/database';if (!building ) {setupMyDatabase ();}export functionload () {// ...}
Preview your apppermalink
Run the preview
script to look at your app locally after the production build is done. Note that this does not yet include adapter-specific adjustments like the platform
object.
Adapterspermalink
Before you can deploy your SvelteKit app, you need to adapt it for your deployment target. Adapters are small plugins that take the built app as input and generate output for deployment. Read more about them in adapters.