0Pricing
Sveltejs Academy · Lesson

The Dev Server and Hot Module Replacement

Run the development server and understand how HMR keeps your browser in sync.

The Dev Server and Hot Module Replacement is a free Sveltejs Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Sveltejs Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What HMR Is

Hot Module Replacement updates only the modules that changed, without a full page reload. Your application state usually survives.

Start the Server

The dev script starts Vite, which serves your code with HMR enabled out of the box.

npm run dev

Watch the Terminal

Vite prints the local URL (default http://localhost:5173) and the network URL if you pass --host.

Save to Update

Edit any .svelte or JS file and save. The browser updates instantly, often within milliseconds.

State Preservation

Svelte preserves component state across HMR updates when possible. A counter at 5 stays at 5 after a markup tweak.

Full Reload Triggers

Some changes force a full reload: config files, server hooks, or import errors. Vite tells you in the console.

Network Access

Pass --host to expose the dev server on your LAN so you can test on a phone.

npm run dev -- --host

Port Conflicts

If port 5173 is taken, Vite picks the next free port. You can also force a port with --port 4000.

Browser DevTools

Open browser DevTools to see source maps that point back to your original .svelte files for accurate stack traces.

Error Overlay

Syntax or runtime errors appear as an overlay in the browser. Fix the code; the overlay disappears on save.

Stopping the Server

Press Ctrl+C in the terminal to stop the dev server. Re-run npm run dev to restart it.

Quick Check

What does HMR do?

Recap

You can start the dev server, benefit from HMR, expose it on your network, and recover from errors via the overlay.

Frequently asked questions

Is the “The Dev Server and Hot Module Replacement” lesson free?

Yes — the full text of “The Dev Server and Hot Module Replacement” is free to read here on the web, and the Sveltejs Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Sveltejs Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Dev Server and Hot Module Replacement”?

Run the development server and understand how HMR keeps your browser in sync. You practise Sveltejs Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Sveltejs Academy?

No prior experience is required. Sveltejs Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Dev Server and Hot Module Replacement” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Sveltejs Academy lesson?

Yes. Every Sveltejs Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Is Svelte and Why It Compiles
  2. Creating a Project with npm create svelte
  3. Project Structure: src routes static
  4. The Dev Server and Hot Module Replacement
← Back to Sveltejs Academy