A development server helps you see your app live as you build it. HMR (Hot Module Replacement) updates parts of your app instantly without reloading the whole page.
Development server and HMR in Svelte
npm run dev
This command starts the development server with HMR enabled by default in SvelteKit or Vite projects.
You usually run this in your project folder terminal to start live reloading.
npm run dev
vite --host
This simple Svelte component shows a button that increases a count when clicked. When you run npm run dev, the development server shows this button. If you change the text or logic, HMR updates the page instantly without full reload.
<script> let count = 0; </script> <button on:click={() => count++} aria-label="Increment count"> Count: {count} </button>
HMR keeps your app state, so you don't lose data when you change code.
Use the browser's developer tools console to see errors or logs while running the dev server.
Development server is only for coding time; for production, build your app with npm run build.
Development server shows your app live and updates it as you code.
HMR updates only changed parts instantly without full page reload.
Run npm run dev to start the server with HMR in Svelte projects.
Practice
Solution
Step 1: Understand the role of the development server
The development server runs your app locally and shows live updates as you make changes.Step 2: Differentiate from production tasks
Compiling for production, deploying, and minifying are separate steps done after development.Final Answer:
To show your app live and update it as you code -> Option DQuick Check:
Development server = live updates [OK]
- Confusing development server with production build
- Thinking it deploys the app
- Assuming it minifies code automatically
Solution
Step 1: Identify the standard Svelte dev command
In Svelte projects,npm run devstarts the development server with HMR enabled.Step 2: Understand other commands
npm run buildcreates production files;npm startandnpm run serveare not standard for Svelte dev server.Final Answer:
npm run dev -> Option BQuick Check:
Start dev server = npm run dev [OK]
- Using npm run build instead of dev
- Confusing npm start with npm run dev
- Trying npm run serve which is not default
<p> tag and save the file?Solution
Step 1: Understand Hot Module Replacement (HMR) behavior
HMR updates only the changed parts of the app instantly without reloading the whole page.Step 2: Apply to text change in <p> tag
Changing text inside the paragraph triggers HMR to update that text immediately, preserving app state.Final Answer:
Only the changed text updates instantly without full reload -> Option CQuick Check:
HMR updates changed parts instantly [OK]
- Thinking full page reload happens on every change
- Believing manual refresh is needed
- Assuming app crashes on text change
npm run dev but the browser does not update when you change your Svelte files. What is the most likely cause?Solution
Step 1: Check if development server is active
If the dev server is not running or crashed, no updates or HMR can happen.Step 2: Evaluate other options
Not saving files prevents changes but usually obvious; using build command doesn't start dev server; browser cache disabled does not stop updates.Final Answer:
The development server is not running or crashed -> Option AQuick Check:
Dev server running = updates work [OK]
- Assuming browser cache blocks updates
- Not saving files before expecting changes
- Confusing build command with dev server
Solution
Step 1: Understand state preservation during updates
HMR updates only changed modules without reloading the whole page, preserving app state like variables and UI state.Step 2: Contrast with other options
Full reload resets state; production build is unrelated to live updates; manual refresh loses state.Final Answer:
Hot Module Replacement (HMR) -> Option AQuick Check:
Keep state during updates = HMR [OK]
- Thinking full reload keeps state
- Confusing production build with dev features
- Relying on manual refresh to keep state
Ready to prove it?
Pass the test and this pattern moves unknown
