Course contentsShow
← Web Development
Lesson 1380 of 2,98225. Build Tools and BundlersFree lesson

Building for Production with Vite

Running vite build to create optimized production bundles using Rollup under the hood.

Building for Production with Vite

You'll learn how to transform your development code into an optimized, production-ready bundle using Vite's build command.

What Happens During a Production Build

Throughout development, Vite serves your code using native ES modules for blazing-fast updates. But when it's time to deploy, you need optimized, bundled files that load efficiently for end users. That's where vite build comes in.

When you run the build command, Vite switches gears entirely. Under the hood, it uses Rollup — a powerful JavaScript bundler — to create highly optimized production assets. Think of it like packing a suitcase: during development, your clothes (code) are spread out for easy access, but for travel (production), everything gets carefully folded, compressed, and organized.

Running the Build Command

npm run build

Or directly:

vite build

This command analyzes your project starting from index.html, follows all module imports, and produces optimized output in the dist folder by default. The result includes:

  • Minified JavaScript with dead code removed
  • Bundled and code-split chunks for optimal loading
  • Hashed filenames for cache-busting (e.g., app.abc123.js)
  • Optimized CSS extracted into separate files
  • Compressed assets ready for deployment

The beauty is that Vite handles all this complexity automatically. Your development experience stays fast with native ESM, while production users get perfectly optimized bundles.

Key Takeaway: Running vite build leverages Rollup under the hood to transform your development code into optimized, minified, and properly bundled production assets ready for deployment.