📖 Scenario: You want to create a simple Svelte app that can be deployed as a static website. This means the app will be pre-built into static files that can be served by any web server without needing a backend.
🎯 Goal: Build a Svelte project configured to use the static adapter for deployment. You will set up the project data, configure the adapter, build the main page, and finalize the deployment setup.
📋 What You'll Learn
Create a basic Svelte component with a greeting message
Add a configuration file to use the static adapter
Build the main page with a heading and paragraph
Complete the adapter export for static deployment
💡 Why This Matters
🌍 Real World
Static adapter deployment is used to build websites that can be hosted on simple web servers or CDNs without needing a backend server.
💼 Career
Knowing how to configure static deployment is important for frontend developers working with SvelteKit to deliver fast, scalable, and easy-to-host web apps.
Progress0 / 4 steps
1
Create the main Svelte component
Create a file named src/routes/+page.svelte with a <script> block that defines a variable greeting set to "Welcome to Static Svelte!". Then add an <h1> element that displays the greeting variable.
Svelte
Hint
Use let greeting = "Welcome to Static Svelte!"; inside the <script> block and display it inside <h1>.
2
Add static adapter configuration
Create a file named svelte.config.js and import adapter-static from @sveltejs/adapter-static. Then export a default configuration object with a property kit.adapter set to the imported adapter().
Svelte
Hint
Import adapter-static and set kit.adapter to adapter() in the exported config object.
3
Add a paragraph to the main page
In the src/routes/+page.svelte file, add a <p> element below the <h1> that says "This site is ready for static deployment."
Svelte
Hint
Add a paragraph tag with the exact text below the heading.
4
Export the adapter for deployment
In the svelte.config.js file, ensure the adapter-static is properly exported by adding export default with the kit.adapter set to adapter(). This completes the static adapter deployment setup.
Svelte
Hint
Make sure the export default includes kit.adapter = adapter() to complete the setup.
Practice
(1/5)
1. What is the main purpose of the static adapter in a SvelteKit project?
easy
A. To add real-time communication features
B. To enable server-side rendering with dynamic data
C. To connect the app to a database automatically
D. To generate static files for hosting without a backend server
Solution
Step 1: Understand what static adapter does
The static adapter converts your SvelteKit app into static files like HTML, CSS, and JS.
Step 2: Identify the hosting benefit
These static files can be hosted easily on any static hosting service without needing a backend server.
Final Answer:
To generate static files for hosting without a backend server -> Option D
Quick Check:
Static adapter = static files for hosting [OK]
Hint: Static adapter means no backend, just static files [OK]
Common Mistakes:
Confusing static adapter with server-side rendering
Thinking it connects to databases
Assuming it adds dynamic real-time features
2. Which code snippet correctly sets up the static adapter in svelte.config.js?
easy
A. export default {
kit: {
adapter: '@sveltejs/adapter-static'
}
};
B. import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter()
}
};
C. import staticAdapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: staticAdapter
}
};
D. import adapter from '@sveltejs/adapter-node';
export default {
kit: {
adapter: adapter()
}
};
Solution
Step 1: Check import statement
The static adapter must be imported from '@sveltejs/adapter-static' and assigned to a variable.
Step 2: Confirm adapter usage
The adapter must be called as a function: adapter() inside the kit.adapter property.
Final Answer:
Correct import and adapter() call in svelte.config.js -> Option B
Quick Check:
Import + adapter() call = correct setup [OK]
Hint: Import adapter and call it as a function in config [OK]
Common Mistakes:
Forgetting to call adapter() as a function
Importing wrong adapter package
Assigning adapter without calling it
3. Given this svelte.config.js snippet, what will be the output folder after building?