Sveltejs Academy · Lesson

Building and Previewing

Run vite build and vite preview to verify your production build locally.

Lesson 4 of 413 steps

Building and Previewing is a free Sveltejs Academy lesson on CoddyKit. This is 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, and your progress syncs across the web and the CoddyKit app. The Sveltejs Academy course includes 4 lessons in total.

Build Command

Run the build script to create a production-ready output.

npm run build

What Build Does

Vite bundles, tree-shakes, and minifies your code. SvelteKit applies the chosen adapter.

Preview Locally

Use the preview script to test the production build locally.

npm run preview

Why Preview

Preview is closer to production than dev: it serves the built bundles, not HMR-instrumented code.

Build Output

The output goes to build/ by default. Each adapter customizes the structure.

Build Errors

TypeScript errors and import issues surface here. Fix before deploying.

Performance Audit

Run Lighthouse against npm run preview to gauge real performance.

Bundle Analysis

Add vite-bundle-visualizer or rollup-plugin-visualizer to inspect bundle composition.

Environment Files

Production builds use .env.production by default; dev uses .env.

Source Maps

Enable production source maps for error monitoring, balancing privacy vs debuggability.

CI Builds

Run build in CI before deploying to catch issues early.

Quick Check

What does npm run preview do?

Recap

Use build for production and preview for local production-like testing before deployment.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
41
Lessons
163

Frequently Asked Questions

Is the “Building and Previewing” lesson free?

Yes — the full text of “Building and Previewing” is free to read here on the web. 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. The Sveltejs Academy course includes 4 lessons in total.

What will I learn in “Building and Previewing”?

Run vite build and vite preview to verify your production build locally. 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, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Building and Previewing” 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. adapter-static for Static Sites
  2. adapter-node for Node.js Server
  3. adapter-vercel and adapter-cloudflare
  4. Building and Previewing
← Back to Sveltejs Academy