Adapter configuration helps SvelteKit know how to build your app for different environments like static sites or servers.
Adapter configuration in Svelte
import adapter from '@sveltejs/adapter-node'; export default { kit: { adapter: adapter({ // adapter options here }) } };
import adapter from '@sveltejs/adapter-static'; export default { kit: { adapter: adapter({ pages: 'build', assets: 'build', fallback: null }) } };
import adapter from '@sveltejs/adapter-node'; export default { kit: { adapter: adapter({ out: 'build' }) } };
This example configures SvelteKit to build a static site. The pages and assets will be placed in the 'public' folder. The fallback page is 'index.html' for single-page app behavior.
import adapter from '@sveltejs/adapter-static'; export default { kit: { adapter: adapter({ pages: 'public', assets: 'public', fallback: 'index.html' }) } };
Always install the adapter package you want to use with npm or yarn before configuring.
Adapters control how your app is built and deployed, so choose one that fits your hosting environment.
Check adapter documentation for specific options you can set.
Adapter configuration tells SvelteKit how to build your app for different environments.
You import and set an adapter in the kit.adapter property in svelte.config.js.
Different adapters are for static sites, Node servers, or other platforms.
Practice
Solution
Step 1: Understand adapter role
An adapter configures how SvelteKit prepares the app for deployment.Step 2: Identify adapter purpose
It tells SvelteKit which environment (static, Node, etc.) to target when building.Final Answer:
To tell SvelteKit how to build and deploy the app for a specific environment -> Option AQuick Check:
Adapter = build target config [OK]
- Confusing adapters with styling or state management
- Thinking adapters handle user events
- Assuming adapters are for routing
svelte.config.js?Solution
Step 1: Check import syntax
The adapter is imported as default from '@sveltejs/adapter-static'.Step 2: Verify export structure
The adapter is set inside thekitproperty as a function calladapter().Final Answer:
import adapter from '@sveltejs/adapter-static'; export default { kit: { adapter: adapter() } }; -> Option BQuick Check:
Import default + kit.adapter = import adapter from '@sveltejs/adapter-static'; export default { kit: { adapter: adapter() } }; [OK]
- Placing adapter outside the kit property
- Using require() instead of import
- Not calling adapter as a function
svelte.config.js snippet, what adapter is being used and what does it imply?
import adapter from '@sveltejs/adapter-node';
export default {
kit: {
adapter: adapter()
}
};Solution
Step 1: Identify adapter import
The adapter imported is '@sveltejs/adapter-node', which targets Node.js servers.Step 2: Understand adapter effect
Using this adapter means the app will be built to run on a Node.js server environment.Final Answer:
Node adapter; app will run on a Node.js server -> Option DQuick Check:
adapter-node = Node server build [OK]
- Confusing adapter-node with static adapter
- Assuming no adapter means static build
- Thinking adapter-node is for serverless
svelte.config.js?
import adapter from '@sveltejs/adapter-static';
export default {
adapter: adapter()
};Solution
Step 1: Check adapter placement
The adapter must be set inside thekitproperty, not directly on the export object.Step 2: Confirm correct structure
Correct config isexport default { kit: { adapter: adapter() } }.Final Answer:
The adapter property should be inside the kit object -> Option AQuick Check:
kit.adapter required inside kit [OK]
- Placing adapter at top level instead of inside kit
- Forgetting to call adapter as a function
- Incorrect import syntax
svelte.config.js to achieve this, and why?Solution
Step 1: Identify deployment goal
The goal is a fully static site with pre-rendered pages.Step 2: Match adapter to goal
'@sveltejs/adapter-static' builds static HTML files suitable for static hosting.Step 3: Exclude other options
Node adapter runs a server, Vercel adapter targets serverless, and no adapter means no specific build target.Final Answer:
Use '@sveltejs/adapter-static' because it builds static HTML files for hosting on any static server -> Option CQuick Check:
Static site needs adapter-static [OK]
- Using Node adapter for static deployment
- Assuming no adapter builds static by default
- Confusing serverless with static hosting
Ready to prove it?
Pass the test and this pattern moves unknown
