Build Tools & Vite
Why build tools?
Modern projects use many files, npm packages, TypeScript, JSX and CSS tools. A build tool:
- runs a dev server with instant reload while you code,
- bundles files for production,
- minifies code (smaller downloads),
- transforms TypeScript and JSX into plain JavaScript,
- adds content hashes to file names for long-term caching.
Vite: the fast, modern standard
npm create vite@latest my-app # choose Vanilla, React, Vue, Svelte…
cd my-app
npm install
npm run dev # http://localhost:5173
npm run build # optimised files in dist/
npm run preview # test the production build
- The dev server serves native ES modules, so it starts in milliseconds.
- HMR (hot module replacement) updates the page without losing its state.
- Production builds are bundled with Rollup.
Environment variables
Create .env with VITE_API_URL=https://api.example.com and read it as import.meta.env.VITE_API_URL. ⚠️ Every VITE_ variable ends up public in the browser bundle; never put secrets there.
Other tools you'll hear about
Webpack (older, very configurable), esbuild (a very fast bundler), Parcel (zero config), Next.js and Nuxt (full frameworks with their own build setup).
Code quality
- ESLint finds bugs and bad patterns.
- Prettier formats code automatically.
- TypeScript adds types, so many bugs are caught before running.
Example
# Create a React + Vite project
npm create vite@latest my-react-app -- --template react
cd my-react-app
npm install
npm run dev # open http://localhost:5173
# Production build
npm run build # output in dist/ — upload to Netlify, Vercel, etc.
# .env (public values only!)
# VITE_SUPABASE_URL=https://xxxx.supabase.co
# In code: import.meta.env.VITE_SUPABASE_URL
# 💻 Run on a computer with Node.js 18+