Skip to content

Commit

Permalink
docs: add general build docs
Browse files Browse the repository at this point in the history
closes #8500
  • Loading branch information
dummdidumm committed Jan 13, 2023
1 parent f6af422 commit 8839f3c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions documentation/docs/20-core-concepts/45-building-your-app.md
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 [adapters docs](/docs/adapters)).

## 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#supported-environments-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).

0 comments on commit 8839f3c

Please sign in to comment.