0Pricing
Sveltejs Academy · Lesson

Building and Previewing

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

Building and Previewing 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.

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.

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, 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 “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; 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 “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