📖 Scenario: You are building a simple SvelteKit app that you want to deploy to a static hosting service. To do this, you need to configure the correct adapter in your project.
🎯 Goal: Configure the SvelteKit project to use the @sveltejs/adapter-static adapter so it can be built as a static site.
📋 What You'll Learn
Create a svelte.config.js file with the basic SvelteKit config
Import @sveltejs/adapter-static and assign it to a variable called adapter
Set the adapter property in the config to the imported adapter
Export the config as the default export
💡 Why This Matters
🌍 Real World
When deploying SvelteKit apps, you must configure the correct adapter to match your hosting environment, such as static hosting or Node servers.
💼 Career
Understanding adapter configuration is essential for frontend developers working with SvelteKit to prepare apps for deployment.
Progress0 / 4 steps
1
Create the basic SvelteKit config
Create a file called svelte.config.js and write a constant called config that is an object with an empty kit property.
Svelte
Hint
Start by creating a constant named config with an object that has a kit property set to an empty object.
2
Import the static adapter
Add an import statement at the top of svelte.config.js to import @sveltejs/adapter-static and assign it to a variable called adapter.
Svelte
Hint
Use the ES module import syntax to bring in @sveltejs/adapter-static as adapter.
3
Configure the adapter in the kit property
Inside the config object, set the adapter property inside kit to the imported adapter variable.
Svelte
Hint
Inside the kit object, add adapter: adapter to tell SvelteKit to use the static adapter.
4
Export the config as default
Add a default export statement to export the config object from svelte.config.js.
Svelte
Hint
Use export default config; to make the config available to SvelteKit.
Practice
(1/5)
1. What is the main purpose of an adapter in a SvelteKit project?
easy
A. To tell SvelteKit how to build and deploy the app for a specific environment
B. To style the components with CSS
C. To manage state inside components
D. To handle user input events
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 A
Quick Check:
Adapter = build target config [OK]
Hint: Adapters define deployment targets for your app [OK]
Common Mistakes:
Confusing adapters with styling or state management
Thinking adapters handle user events
Assuming adapters are for routing
2. Which of the following is the correct way to import and set an adapter in svelte.config.js?
easy
A. import adapter from '@sveltejs/adapter-static';
export default {
adapter: adapter()
};
B. import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter()
}
};
The adapter property should be inside the kit object -> Option A
Quick Check:
kit.adapter required inside kit [OK]
Hint: Always put adapter inside kit property in svelte.config.js [OK]
Common Mistakes:
Placing adapter at top level instead of inside kit
Forgetting to call adapter as a function
Incorrect import syntax
5. You want to deploy a SvelteKit app as a fully static site with pre-rendered pages. Which adapter configuration should you use in svelte.config.js to achieve this, and why?
hard
A. Use '@sveltejs/adapter-vercel' because it only supports serverless functions
B. Use '@sveltejs/adapter-node' because it runs the app on a Node.js server
C. Use '@sveltejs/adapter-static' because it builds static HTML files for hosting on any static server
D. No adapter is needed; SvelteKit builds static sites by default
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 C
Quick Check:
Static site needs adapter-static [OK]
Hint: Static sites need adapter-static for pre-rendered HTML [OK]
Common Mistakes:
Using Node adapter for static deployment
Assuming no adapter builds static by default
Confusing serverless with static hosting
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.