-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
documentation/docs/20-core-concepts/45-building-your-app.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: Building Your App | ||
--- | ||
|
||
Building 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](/docs/page-options#prerender) 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 [/docs/adapters](adapters docs)). | ||
|
||
## During the build | ||
|
||
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`: | ||
|
||
```js | ||
/// file: +layout.server.js | ||
// @filename: ambient.d.ts | ||
declare module '$lib/server/database' { | ||
export function setupMyDatabase(): void; | ||
} | ||
|
||
// @filename: index.js | ||
// ---cut--- | ||
import { building } from '$app/environment'; | ||
import { setupMyDatabase } from '$lib/server/database'; | ||
|
||
if (!building) { | ||
setupMyDatabase(); | ||
} | ||
|
||
export const load() { | ||
// ... | ||
} | ||
``` | ||
|
||
## Preview your app | ||
|
||
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](/docs/adapters#platform-specific-context). | ||
|
||
## Adapters | ||
|
||
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](/docs/adapters). |