Vite (French for “fast”) is a next-generation frontend build tool created by Evan You, the creator of Vue.js. After using it for several projects, I can confirm it lives up to its name. Development server starts in milliseconds, hot module replacement is instantaneous, and the overall developer experience is transformative.
Why Vite is Fast
Traditional bundlers (webpack, Rollup) bundle your entire application before serving it. Vite takes a different approach:
- Native ES Modules: During development, Vite serves files directly using browser-native ES modules. No bundling step!
- esbuild: Dependencies are pre-bundled using esbuild, which is 10-100x faster than JavaScript bundlers
- On-demand Compilation: Source code is transformed only when requested by the browser
- HMR Over Native ESM: Hot updates are precise and fast because the module graph is explicit
Getting Started
# Create a new project
npm create vite@latest my-app
# Choose a template:
# - vanilla / vanilla-ts
# - vue / vue-ts
# - react / react-ts
# - preact / preact-ts
# - svelte / svelte-ts
cd my-app
npm install
npm run dev # Server starts in ~200ms!
Configuration
// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
server: {
port: 3000,
proxy: {
'/api': 'http://localhost:5000'
}
},
build: {
outDir: 'dist',
sourcemap: true,
rollupOptions: {
// Rollup options for production build
}
},
resolve: {
alias: {
'@': '/src'
}
}
})
Import Features
// Static asset imports
import logo from './assets/logo.png' // Returns URL
// JSON
import data from './data.json' // Default: parsed JSON
// CSS Modules
import styles from './Button.module.css'
<button className={styles.button}>
// Web Workers
import Worker from './worker.js?worker'
const worker = new Worker()
// Glob imports
const modules = import.meta.glob('./components/*.vue')
When to Use Vite
Vite excels for:
- New projects with modern browsers as targets
- Vue, React, or Svelte applications
- Development where speed matters (large codebases)
- Teams wanting simpler configuration than webpack
Consider alternatives if you need legacy browser support (IE11) or have complex webpack configurations with no Vite equivalent.
Key Takeaways
- Vite uses native ES modules for instant dev server startup
- esbuild pre-bundles dependencies for 10-100x faster builds
- Works with Vue, React, Svelte and vanilla JavaScript
- Production builds use Rollup for optimized output
References
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.