Skip to main content
Frontend Engineering

Vite Build Tool & Dev Server

Essential

Next-generation frontend tooling, lightning-fast HMR dev server, Rollup production bundles, and environment variables.

Instant Copy & SearchProduction Flagged SyntaxCurrent Flag Reference

Vite Build Tool & Dev Server Interactive Command Directory

Browse, search, and copy battle-tested commands & syntax recipes (16 Total Commands).

16+ Verified Recipes
Project Creation--template react-ts
npm create vite@latest my-app -- --template react-ts

Scaffold a new TypeScript React project with preconfigured Vite setup.

Dev Server--host, --port, --open
vite --host 0.0.0.0 --port 3000 --open

Start development server binding to all network interfaces and open browser.

Production Buildbuild --mode
vite build --mode production

Compile production bundle with Rollup tree-shaking and minification into dist/.

Preview Buildpreview
vite preview --port 8080

Locally serve the production dist/ bundle to test before cloud deployment.

Environment Variablesimport.meta.env
const apiUrl = import.meta.env.VITE_API_URL;

Access client-side environment variables prefixed with VITE_.

Path Aliasesresolve.alias
// vite.config.ts resolve: { alias: { '@': path.resolve(__dirname, './src') } }

Configure clean root import aliases avoiding messy relative path references.

API Dev Proxyserver.proxy
server: { proxy: { '/api': { target: 'http://localhost:8000', changeOrigin: true } } }

Forward local frontend API requests to backend services preventing CORS restrictions.

Glob Importsimport.meta.glob
const modules = import.meta.glob('./modules/*.ts');

Dynamically discover and import multiple modules matching a file pattern.

Raw File Imports?raw
import rawSvg from './icon.svg?raw';

Import file contents directly as raw UTF-8 string data using the ?raw suffix.

Web Worker Bundlingnew Worker(..., { type: 'module' })
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });

Spawn TypeScript web workers with automatic Vite bundling and HMR support.

Bundle Size Visualizationvite-bundle-visualizer
npx vite-bundle-visualizer

Generate interactive treemap visualization of Rollup output chunks to identify bloat.

Manual Code SplittingmanualChunks
build: { rollupOptions: { output: { manualChunks: { vendor: ['react', 'react-dom'] } } } }

Partition heavy third-party vendor libraries into long-lived cached browser chunks.

Cache Invalidation--force
vite --force

Purge pre-bundled dependency cache in node_modules/.vite to resolve stale library errors.

Vitest Integrationvitest
// vitest.config.ts export default defineConfig({ test: { globals: true, environment: 'jsdom' } });

Zero-overhead unit test configuration sharing identical Vite transform pipeline.

Subpath Base URLbase
// vite.config.ts export default defineConfig({ base: '/my-subpath/' });

Set custom asset deployment base URL for reverse proxies and GitHub Pages.

Environment Detectionimport.meta.env
const isDev = import.meta.env.DEV; const mode = import.meta.env.MODE;

Inspect runtime build environment and custom mode variables.

Zero Setup100% In-Browser Execution

Companion Developer Tools & Playgrounds

Accelerate command execution and syntax debugging with HelloAIHub suite of interactive tools.

Explore all developer tools

Vite Build Tool & Dev Server: Command Groups & Quick Index

16 indexed entries across 16 sections
Project Creation1 items
Dev Server1 items
Production Build1 items
Preview Build1 items
Environment Variables1 items
Path Aliases1 items
API Dev Proxy1 items
Glob Imports1 items
Raw File Imports1 items
Web Worker Bundling1 items
Bundle Size Visualization1 items
Manual Code Splitting1 items
Cache Invalidation1 items
Vitest Integration1 items
Subpath Base URL1 items
Environment Detection1 items

Highlighted Flags & Syntax Examples in Vite Build Tool & Dev Server

npm create vite@latest my-app -- --template react-ts

Scaffold a new TypeScript React project with preconfigured Vite setup.

Flags: --template react-ts
vite --host 0.0.0.0 --port 3000 --open

Start development server binding to all network interfaces and open browser.

Flags: --host, --port, --open
vite build --mode production

Compile production bundle with Rollup tree-shaking and minification into dist/.

Flags: build --mode
vite preview --port 8080

Locally serve the production dist/ bundle to test before cloud deployment.

Flags: preview

Frequently Asked Questions

Expert recommendations, common traps, and production best practices for Vite Build Tool & Dev Server.

Why is Vite significantly faster during development than Webpack?

Webpack bundles your entire application into memory before serving it. Vite leverages native browser ES Modules (ESM), serving source code on-demand per request without bundling. For pre-bundling external dependencies, Vite uses Esbuild (written in Go), which is 10-100x faster than JavaScript-based bundlers.

Why must client-side environment variables start with VITE_?

To prevent accidental leakage of sensitive server environment variables (like secret database keys) to the client browser bundle, Vite only exposes variables that explicitly begin with the VITE_ prefix.

How does Vite's Native ESM-based dev server work compared to bundle-based bundlers?

Traditional bundlers (Webpack) must crawl and bundle your entire codebase before serving. Vite serves source code over native ES Modules (ESM) in the browser: the browser requests only the modules needed for the current screen, and Vite transforms them on the fly. This keeps dev server startup instant (milliseconds) regardless of application size.

How does Vite handle pre-bundling of CommonJS dependencies with esbuild?

Many npm packages still ship as CommonJS or UMD. On startup, Vite uses esbuild (written in Go) to pre-bundle these dependencies into single ESM files in 'node_modules/.vite'. This converts CommonJS to ESM and consolidates packages with hundreds of internal files into single HTTP requests.

What is the difference between esbuild (used during dev) and Rollup (used for production build) in Vite?

Vite uses esbuild during development for pre-bundling and TypeScript transpilation because esbuild is 10x–50x faster. For production builds, Vite uses Rollup because Rollup provides mature tree-shaking, sophisticated code-splitting, CSS code-splitting, and a robust plugin ecosystem.

How do you configure code splitting and manualChunks in Vite to optimize initial page load?

Under 'build.rollupOptions.output.manualChunks', you can define an object or function mapping package names to chunk names. Grouping large frameworks (like React, lodash, or Three.js) into separate vendor chunks allows browsers to cache them permanently across your site's application code deployments.

Cross-Hub Skill Acceleration

Combine command lookups with active coding interviews and complete career paths.

Need More Cheat Sheets?

Explore developer cheat sheets and syntax guides on HelloAIHub.

Browse All Cheat Sheets