vite
Vite
Vite is a frontend build tool that serves source files via native ES modules during development and uses Rollup for optimized production builds.
Documentation
Key Capabilities
Vite has several built-in features developers commonly add external packages for:
- TypeScript: Transpiled natively via esbuild (20-30x faster than tsc) — no
ts-loaderorbabel-preset-typescriptneeded. Note: Vite only transpiles, it does not type-check; runtsc --noEmitseparately. - CSS Modules: Any file named
*.module.cssis automatically a CSS module returning a scoped object — no extra plugin needed. - CSS Pre-processors:
.scss,.sass,.less,.stylwork out of the box — justnpm installthe preprocessor itself, no Vite plugin required. - JSON named imports:
import { version } from './package.json'works and is tree-shaken — no need for a JSON loader plugin. - Glob imports:
import.meta.glob('./dir/*.js')handles dynamic multi-module imports natively — norequire.contextworkaround needed. - Web Workers: Standard
new Worker(new URL('./worker.js', import.meta.url))syntax is supported natively alongside the?workerquery suffix. - Static asset transforms: Query suffixes
?url,?raw,?inlinechange how assets are imported — no file-loader/url-loader equivalents needed. - Env variables: Built-in
.envfile loading withimport.meta.env— nodotenv-webpackor similar needed.
Best Practices
VITE_ prefix is required for client exposure. Only variables prefixed with VITE_ are exposed to client code via import.meta.env. Variables without this prefix are intentionally hidden to prevent secrets from leaking into the browser bundle. Coming from webpack's DefinePlugin, this is the single most common missed step.
Env variables are always strings. import.meta.env.VITE_PORT is "3000" not 3000. Cast explicitly: Number(import.meta.env.VITE_PORT) or import.meta.env.VITE_FLAG === 'true'.
.env changes require a server restart. Vite reads .env files at startup — modifying them does not trigger HMR. Many developers waste time waiting for a reload that never comes.
NODE_ENV and --mode are independent. Running vite build --mode staging still sets NODE_ENV=production. To change NODE_ENV, set it as a shell variable: NODE_ENV=development vite build.
More from mikkelkrogsholm/dev-skills
meilisearch
Meilisearch — fast, open-source search engine with typo tolerance, faceted search, and AI-powered hybrid search. Use when building with Meilisearch or asking about its index configuration, search parameters, filters, facets, API keys, geosearch, ranking rules, or integration with JavaScript/TypeScript clients. Fetch live documentation for up-to-date details.
42shadcn-ui
shadcn/ui — copy-owned React component library built on Radix UI and Tailwind CSS. Use when building with shadcn/ui or asking about its components, CLI, theming, configuration, or integration with Next.js, Vite, Remix, or other frameworks. Fetch live documentation for up-to-date details.
10zod
Zod — TypeScript-first schema validation with static type inference. Use when building with Zod or asking about schema definitions, type inference, parsing, transformations, refinements, coercion, error handling, or integration with forms, APIs, or tRPC. Fetch live documentation for up-to-date details.
10bun
Bun — fast all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building with Bun, running TypeScript, managing packages with bun install, writing tests with bun test, or asking about Bun APIs, configuration, or Node.js migration. Fetch live documentation for up-to-date API details.
9better-auth
Better Auth — framework-agnostic authentication and authorization framework for TypeScript. Use when building with Better Auth or asking about its APIs, configuration, plugins, session management, OAuth, or integration. Fetch live documentation for up-to-date details.
7react
React — JavaScript library for building user interfaces with components. Use when building with React or asking about hooks, state management, effects, Server Components, Suspense, or any React APIs, patterns, or configuration. Fetch live documentation for up-to-date details.
7