Vite Introduction
Vite Introduction explains Vite as modern frontend development and build tooling, covering native ES modules, TypeScript and JSX transformation, HMR, React Fast Refresh, plugins, configuration, proxies, environment variables, production bundling, assets, Spring Boot integration, and enterprise architecture.
Learning Objectives
By the end of this lesson, you will be able to:
- Understand what Vite is and why modern React projects use it.
- Understand the problem Vite solves.
- Understand the difference between Vite and React.
- Understand Vite's development-server architecture.
- Understand how Vite handles ES modules during development.
- Understand Vite's role in JSX and TypeScript development.
- Understand Hot Module Replacement / Fast Refresh.
- Understand Vite plugins.
- Understand Vite configuration.
- Understand environment variables in Vite.
- Understand Vite's production build process.
- Understand Vite's relationship with Rollup and modern production bundling.
- Understand Vite's role in code splitting and asset processing.
- Understand when Vite is appropriate and when a React framework is preferable.
- Troubleshoot common Vite issues.
- Explain Vite confidently in React interviews.
- Understand Vite from a senior/architect perspective.
Introduction
In the previous lessons, we learned:
React↓Project Setup↓React + TypeScript + Vite
But an important question remains:
What exactly is Vite doing in our React application?
A common beginner misconception is:
Vite = React
That's incorrect.
Another misconception is:
Vite = React framework
That's also incorrect.
A better mental model is:
React││ UI library▼Your Application││ development/build tooling▼Vite│├── Development Server├── Module Handling├── Fast Refresh integration├── Build└── Asset Processing
So:
React helps you build the UI. Vite helps you develop and build the application.
What Is Vite?
Vite is a modern frontend build tool and development server.
It was created by Evan You, the creator of Vue, but Vite is not limited to Vue.
It supports multiple frontend ecosystems, including:
ReactVueSveltePreactVanilla JavaScript
For our course, we're using:
Vite+React+TypeScript
The official Vite documentation describes Vite as a frontend tooling system providing a fast development experience and optimized production builds. Vite Documentation
Why Was Vite Needed?
To understand Vite, first understand the traditional frontend build problem.
Imagine a project with:
src/├── App.tsx├── components/├── services/├── hooks/├── pages/└── utils/
The browser needs to execute browser-compatible JavaScript.
But developers may write:
TypeScriptJSXES ModulesCSSImported ImagesModern JavaScript
Therefore, development tooling needs to process these files.
Historically, tools often created a large dependency graph and bundled a significant amount of the application before serving it.
Conceptually:
Source Code│▼Build Tool│▼Dependency Graph│▼Bundle│▼Browser
As projects became larger, this could lead to slower development startup and slower feedback loops.
Vite was designed to improve this development experience.
Vite's Core Idea
The key idea behind Vite's development architecture is:
Use the browser's native ES module support during development and transform modules on demand.
Modern browsers understand:
import { something } from "./module.js";
So instead of unnecessarily bundling the entire application before the browser can start developing, Vite can serve modules individually and transform them when requested.
Conceptually:
Browser││ requests module▼Vite Dev Server│▼Transform requested module│▼Browser
This is one of the fundamental reasons Vite can provide a fast development experience.
Traditional Development Model
A simplified traditional workflow might look like:
Source Files│▼Dependency Graph│▼Bundler│▼Large Development Bundle│▼Browser
When the application becomes large:
More Files↓Larger Graph↓More Processing↓Slower Startup
This is a simplified model; modern bundlers have many optimizations.
Vite Development Model
Vite takes a different approach during development:
Source Files│▼Vite Dev Server│┌───────┼────────┐▼ ▼ ▼Module A Module B Module C│ │ │└───────┼────────┘▼Browser
The browser requests what it needs.
Vite transforms modules as required.
This helps keep development startup and updates fast.
Vite Is Not a Runtime
This is important.
Vite is primarily a development/build tool.
Your production browser application doesn't normally run:
Vite server
Instead:
Development│▼Vite Dev Server│▼Browser
Production:
Source│▼Vite Build│▼Production Assets│▼CDN / Web Server│▼Browser
So Vite is part of your development and build pipeline.
Vite + React Architecture
Our React application looks like:
Developer│▼React + TypeScript│▼Vite┌────────┼─────────┐▼ ▼ ▼Dev Transform BuildServer Modules│ │▼ ▼Browser dist/
This separation is very important.
Creating a Vite React Project
The command we've already used is:
npm create vite@latest techlearningpro-react -- --template react-ts
Then:
cd techlearningpro-react
Install dependencies:
npm install
Start Vite:
npm run dev
The development server will provide a URL, commonly:
http://localhost:5173
The exact port may vary.
What Happens When npm run dev Runs?
Look at:
{"scripts": {"dev": "vite"}}
When you execute:
npm run dev
npm effectively launches:
vite
The flow becomes:
Terminal│▼npm run dev│▼Vite│▼Development Server│▼Browser
What Does the Vite Development Server Do?
The development server is responsible for things such as:
Serving filesTransforming modulesHandling importsProviding HMRProcessing assetsHandling development configuration
For example:
Browser requests:/src/main.tsx↓Vite receives request↓Vite transforms module↓Browser receives module↓Application runs
Native ES Modules
Modern browsers support ES modules.
For example:
import { calculateTotal } from "./cart.js";console.log(calculateTotal());
This is a native module relationship.
Vite can leverage this capability during development.
Conceptually:
main.tsx│├── App.tsx│ ├── Header.tsx│ └── CourseList.tsx│└── styles.css
The browser can request modules through the development server.
Vite handles the transformations necessary for the source format.
What About TypeScript?
Browsers do not execute TypeScript directly.
For example:
interface Course {title: string;}
The browser doesn't understand the TypeScript type syntax.
Vite's development pipeline transforms the source appropriately for browser execution.
This means:
TypeScript│▼Vite Transformation│▼Browser-compatible JavaScript
Important distinction:
Vite does not replace the TypeScript type checker.
In a typical TypeScript project, type checking can be handled separately by TypeScript tooling.
This is why Vite projects often have build commands involving TypeScript checks.
JSX Transformation
React applications commonly use JSX:
function App() {return <h1>Hello React</h1>;}
The browser doesn't directly execute JSX syntax.
The tooling transforms it into JavaScript that React can use.
Conceptually:
JSX│▼Transformation│▼JavaScript│▼Browser
Vite's React integration handles the required transformation pipeline.
Vite React Plugin
A Vite React project commonly uses:
@vitejs/plugin-react
The configuration may look like:
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";export default defineConfig({plugins: [react()]});
The plugin integrates React-specific behavior into Vite.
For example, it supports the React development workflow including Fast Refresh.
What Is Fast Refresh?
Fast Refresh provides rapid feedback while developing React applications.
Imagine:
App.tsx
contains:
<h1>Welcome</h1>
You change it to:
<h1>Welcome to TechLearningPro</h1>
After saving:
Save↓Vite detects change↓React Fast Refresh↓Browser updates
You don't normally need to manually refresh the entire page.
Why Fast Refresh Matters
Imagine developing a large form:
NameAddressPhoneCountryStateCity
You modify a button.
Without a good fast-refresh workflow, you might repeatedly:
Save↓Reload↓Re-enter data↓Navigate back↓Test
Fast Refresh makes the feedback loop much faster.
This improves:
Developer Productivity
rather than directly improving your application's production performance.
Vite HMR
HMR means:
Hot Module Replacement
It allows parts of an application to be updated without performing a complete page reload.
In React development, this works together with React Fast Refresh.
Conceptually:
Developer changes Component│▼Vite│▼HMR update│▼React Refresh│▼Browser
Development vs Production
This is one of the most important Vite concepts.
Development
npm run dev
Focus:
Fast startupFast updatesDebuggingDeveloper experience
Production
npm run build
Focus:
Optimized outputSmall assetsEfficient loadingProduction deployment
These are different optimization goals.
Vite Production Build
When you run:
npm run build
Vite generates production assets.
Conceptually:
React Source│▼Vite Build│├── Transform├── Bundle├── Optimize├── Process Assets└── Generate Chunks│▼dist/
You can inspect the output:
dist/├── index.html└── assets/├── *.js├── *.css└── other assets
Exact filenames depend on the build.
Rollup and Vite
You may hear:
Vite uses Rollup.
Historically and conceptually, this is an important part of understanding Vite's production build architecture.
Vite's production build has traditionally used Rollup, while newer Vite releases also incorporate newer internal build technology and tooling.
The important conceptual distinction is:
Development↓Vite Dev Server↓Native ESM-oriented workflowProduction↓Vite Build↓Production bundling/optimization
Don't reduce Vite to simply:
Vite = Rollup
Vite provides a complete development/build experience around its tooling pipeline.
Why Bundle for Production?
Browsers can load modules individually.
So why bundle?
Production applications benefit from optimization strategies such as:
Code splittingAsset optimizationChunkingMinificationCaching strategiesDependency optimization
Imagine:
1000 JavaScript modules
Sending and managing every module individually may not be optimal.
Production tooling can produce a more efficient asset graph:
Application│├── main.js├── courses.js├── dashboard.js└── vendor/chunks
This can improve network and loading behavior.
Code Splitting
Suppose your application contains:
HomeCoursesDashboardAdminReports
A user visiting Home may not need Admin immediately.
Code splitting allows:
Initial Load│▼Home chunkLater:│▼Dashboard chunk
Conceptually:
Application│├── main.js├── courses.js├── dashboard.js└── admin.js
We'll study this in detail when we reach lazy loading and routing.
Asset Processing
Vite also processes assets.
For example:
CSSImagesSVGFontsJavaScriptTypeScript
Suppose:
import logo from "./assets/logo.png";
Vite understands that this asset is part of the application's dependency graph.
During production:
logo.png│▼Build│▼Optimized / referenced asset
The exact processing depends on the asset type and configuration.
Static Assets
You can also put assets under:
public/
For example:
public/├── robots.txt├── favicon.ico└── images/└── logo.png
Then they can be referenced through their public URL.
The important distinction is:
src/assets↓Part of module/build graphpublic↓Served as static public assets
Choose intentionally.
Vite Configuration
The primary configuration file is:
vite.config.ts
Example:
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";export default defineConfig({plugins: [react()]});
You can configure:
PluginsServerProxyAliasesBuildEnvironment behaviorAsset handling
Development Proxy
A common enterprise problem is:
Browser│▼localhost:5173│▼Backend APIlocalhost:8080
You might encounter CORS issues.
Vite can provide a development proxy.
Conceptually:
Browser│▼Vite│├── /api/users│▼Backend
A simplified configuration can look like:
export default defineConfig({server: {proxy: {"/api": {target: "http://localhost:8080",changeOrigin: true}}}});
Now:
/api/users
can be forwarded to the backend during development.
This is particularly useful when working with:
React+Spring Boot
which is a common enterprise architecture.
Vite Environment Variables
Vite exposes environment variables through:
import.meta.env
For example:
VITE_API_BASE_URL=https://api.example.com
Then:
const apiUrl =import.meta.env.VITE_API_BASE_URL;
The VITE_ prefix is significant for variables intended to be exposed to client-side code.
Environment Modes
Vite supports different modes.
Common concepts include:
developmentproduction
You can have:
.env.env.local.env.development.env.development.local.env.production.env.production.local
For example:
.env.development
might contain:
VITE_API_BASE_URL=http://localhost:8080
while:
.env.production
might contain:
VITE_API_BASE_URL=https://api.techlearningpro.com
Environment Security
This deserves repetition.
If the browser can access:
import.meta.env.VITE_API_KEY
you should assume users can potentially inspect it.
Therefore:
Client configuration≠Secret configuration
Never place:
Database PasswordPrivate Signing KeySecret API Credential
in browser-exposed Vite variables.
Instead:
React│▼Backend API│▼Secret
The backend should protect sensitive credentials.
Vite Dependency Optimization
During development, Vite may optimize dependencies.
Why?
Imagine:
Your App│├── React├── Library A├── Library B└── Library C
Some dependencies may contain many modules or use formats that aren't ideal for direct browser loading.
Vite can pre-bundle dependencies to improve development performance.
Conceptually:
Dependencies│▼Dependency Optimization│▼Faster Development Loading
This is different from your application's final production bundle.
Vite and React Are Separate Concerns
Remember:
React└── Component / UI modelVite├── Dev server├── Module transformation├── HMR├── Build└── Asset handling
This separation is architecturally useful.
You could use React with a different build system.
You could use Vite with another frontend framework.
Therefore:
Vite ≠ React
Vite vs Webpack
This is a common interview question.
A simplified comparison:
| Area | Vite | Traditional Webpack Workflow |
|---|---|---|
| Development | Native ESM-oriented dev server | Bundler-oriented |
| Startup | Typically very fast | Can depend heavily on project size/config |
| HMR | Fast | Mature and powerful |
| Configuration | Often simpler | Highly configurable |
| Production | Optimized build pipeline | Mature production bundling |
| Ecosystem | Modern and growing | Very mature |
| Learning curve | Generally lower | Can be higher |
But don't say:
Webpack is slow and Vite is fast.
That's too simplistic.
Webpack has extensive optimization capabilities and remains widely used.
The better answer is:
Vite uses a different development architecture that can significantly reduce development startup and update overhead, while Webpack provides a highly mature and configurable bundling ecosystem.
Vite vs Create React App
This comparison is increasingly important because many older tutorials still use CRA.
Create React App
create-react-app
was historically a common React project generator.
But:
Create React App was deprecated for new applications by the React team in 2025.
For new projects, use modern React framework tooling or a build tool such as Vite when appropriate.
So:
Old tutorials↓Create React App
versus:
Modern setup↓React FrameworkORVite + React
Vite vs Next.js
This is another important architectural comparison.
Vite
Primarily:
Build Tool+Development Server
Next.js
A React framework providing a broader application model.
Conceptually:
Vite│├── Dev Server├── Build└── Tooling
while a framework may provide:
Framework│├── Routing├── Rendering strategies├── Data loading├── Build├── Deployment integration└── More application conventions
So:
Vite and Next.js aren't direct equivalents.
One is primarily a build tool; the other is an application framework.
When Should You Use Vite?
Vite is a strong choice when you want:
Fast frontend development+React+Client-side application+Control over architecture
Examples:
Admin DashboardInternal Enterprise ToolSPALearning ApplicationData VisualizationFrontend for REST APIs
When Should You Consider a React Framework?
Consider a framework when the application needs things such as:
Server renderingRouting conventionsServer-side capabilitiesData-loading architectureAdvanced deployment integration
For a public production website, these requirements may become important.
React's current documentation recommends considering a framework for new applications. React — Creating a React App
Vite + Spring Boot Architecture
This is especially relevant to enterprise Java developers.
Imagine:
Browser│▼React + Vite││ HTTPS▼Spring Boot API│┌─────────┼─────────┐▼ ▼ ▼Service Database Cache
During development:
Reactlocalhost:5173│▼Vite Proxy│▼Spring Bootlocalhost:8080
During production:
Browser│▼CDN / Web Server│├── React static assets│▼API Gateway / Backend│▼Spring Boot Microservices
This is a very common enterprise architecture.
Vite Development Flow
Let's visualize the complete development cycle:
Developer│▼Edit App.tsx│▼Save│▼Vite detects change│▼Transform module│▼HMR│▼React Fast Refresh│▼Browser updates
This is why Vite feels fast during development.
Vite Production Flow
Production is different:
Developer│▼npm run build│▼Vite Build│├── TypeScript/JSX processing├── Module graph├── Bundling├── Code splitting├── Asset processing└── Optimization│▼dist/│▼CDN / Web Server│▼Users
Common Mistakes
Mistake 1: Thinking Vite is React
Incorrect:
Vite = React
Correct:
React = UI libraryVite = development/build tool
Mistake 2: Using Vite as a production server
Normally:
npm run dev
is for development.
Production should use:
npm run build
and deploy the generated assets through appropriate infrastructure.
Mistake 3: Putting secrets in .env
Environment variables exposed to the browser are not secrets.
Mistake 4: Installing unnecessary plugins
Only install plugins that solve actual project requirements.
Every plugin increases:
ComplexityMaintenanceUpgrade risk
Mistake 5: Changing vite.config.ts without understanding it
Configuration should be intentional.
Don't copy a random configuration from Stack Overflow.
Mistake 6: Confusing HMR with production optimization
HMR improves the developer feedback loop.
It doesn't make your production application automatically faster.
Practical Exercise
Create a new project:
npm create vite@latest vite-learning -- --template react-ts
Then:
cd vite-learningnpm installnpm run dev
Exercise 1 — Change the Application
Open:
src/App.tsx
Replace the component with:
function App() {return (<main><h1>Vite + React</h1><p>This application is powered byReact and Vite.</p></main>);}export default App;
Save the file.
Observe how quickly the browser updates.
Exercise 2 — Inspect the Network
Open browser DevTools.
Go to:
Network
Reload the application.
Observe requests such as:
index.htmlsrc/main.tsxsrc/App.tsx
You can use this to understand the development module-loading model.
Don't worry if the exact requests differ between browser/tool versions.
Exercise 3 — Add a Vite Proxy
Assume your Spring Boot API runs on:
http://localhost:8080
Configure a development proxy:
export default defineConfig({plugins: [react()],server: {proxy: {"/api": {target: "http://localhost:8080",changeOrigin: true}}}});
Then your React code can request:
/api/courses
and Vite can proxy that request during development.
Exercise 4 — Production Build
Run:
npm run build
Then inspect:
dist/
Understand:
src/↓Vite Build↓dist/
The src directory is development source code.
The dist directory is generated production output.
Interview questions & answers
Interview preparation
15 questions grouped by difficulty — expand any card for a model answer and follow-up probe.
Beginner
1What is Vite?
BeginnerModel answer
Vite is a modern frontend development and build tool.
It provides a development server, module transformation, fast development updates, and production build capabilities.
2Is Vite a React framework?
BeginnerModel answer
No.
Vite is primarily a frontend build tool and development server.
React is the UI library.
A React framework provides a broader application architecture.
3Why is Vite fast?
BeginnerModel answer
One major reason is its development architecture based on native browser ES modules and on-demand module transformation rather than requiring the entire application to be bundled before development can start.
4What command starts a Vite application?
BeginnerModel answer
npm run devassuming the project'spackage.jsondefines the standard Vite script.
Intermediate
5What is HMR?
IntermediateModel answer
HMR stands for Hot Module Replacement.
It allows changed modules to be updated in the running development application without requiring a complete page reload.
In React projects, this works together with React Fast Refresh.
6What is the difference between development and production in Vite?
IntermediateModel answer
Development focuses on fast feedback, module serving, and HMR.
Production focuses on generating optimized assets suitable for deployment, including bundling, code splitting, and asset optimization.
7What is vite.config.ts?
IntermediateModel answer
It's Vite's configuration file.
It can configure plugins, development-server behavior, proxies, aliases, build options, and other Vite-specific behavior.
8How does Vite handle TypeScript?
IntermediateModel answer
Vite transforms TypeScript source into browser-compatible JavaScript as part of the development/build pipeline.
Type checking is a separate concern and is typically handled by TypeScript tooling rather than relying solely on Vite's transformation step.
Advanced
9Why would you choose Vite over Webpack?
AdvancedModel answer
I'd choose based on requirements.
Vite provides an excellent modern development experience with fast startup and HMR, while Webpack has a very mature and highly configurable ecosystem.
For a new React SPA, Vite can reduce configuration complexity and provide a fast development workflow.
10Why would you choose Vite instead of Next.js?
AdvancedModel answer
I wouldn't treat them as direct replacements.
js is a React application framework.
If the application is primarily a client-side SPA and I want control over routing and architecture, Vite can be a good fit.
If I need framework-level capabilities such as server rendering or integrated routing/data patterns, I'd evaluate a framework.
11How does Vite improve developer experience?
AdvancedModel answer
Its development server uses a module-oriented approach and transforms modules on demand, which can reduce startup and update overhead.
Combined with HMR and React Fast Refresh, developers get a very fast edit-save-feedback loop.
12Would you standardize Vite across an enterprise?
AdvancedModel answer
I would standardize the tooling where it makes sense, but not blindly.
I'd evaluate application categories.
For client-side applications, Vite can provide a strong standard.
Applications requiring framework-level server capabilities may need a different React architecture.
I'd standardize principles and supported tooling rather than forcing one tool onto every application.
13How would you design a Vite + React + Spring Boot architecture?
AdvancedModel answer
I'd separate frontend and backend responsibilities.
React would handle presentation and client-side interaction, Vite would provide development and production build tooling, and Spring Boot would expose APIs and handle business logic.
During development I'd use a Vite proxy for API routing where useful.
In production I'd deploy the generated frontend assets through a CDN or web server and expose backend APIs separately through an API gateway or suitable infrastructure.
14What are the risks of adding too much Vite configuration?
AdvancedModel answer
Configuration complexity can become technical debt.
Excessive plugins, custom transformations, aliases, proxy rules, and build customization can make upgrades difficult and onboarding slower.
I'd keep configuration minimal and introduce customization only when there is a measurable requirement.
15What would you investigate if Vite became slow?
AdvancedModel answer
I'd first determine whether the problem is development startup, HMR latency, dependency optimization, TypeScript checking, or production build time.
Then I'd inspect the dependency graph, large plugins, custom transformations, file-system watchers, project size, and build configuration.
I'd measure before changing configuration.
Important Architecture Insight
A senior engineer shouldn't think:
Vite makes React fast.
That's incomplete.
Think:
React│▼UI ArchitectureVite│├── Development experience├── Module transformation├── HMR└── Production build
And:
Browser Performance│├── Network├── JavaScript├── Rendering├── Images├── Caching└── Application architecture
Vite can contribute to build and delivery optimization, but it doesn't automatically solve every performance problem.
Final Mental Model
Remember this architecture:
React Application│▼┌─────────────────┐│ Vite │└─────────────────┘│┌────────────────┼────────────────┐▼ ▼ ▼Development Transformation BuildServer │ ││ │ │▼ ▼ ▼HMR JSX/TS Production│ Modules Assets│ │ │▼ ▼ ▼Browser Browser Code dist/│ │└───────┬────────┘▼Deploy
The most important sentence from this lesson is:
React defines how we build the UI; Vite provides the modern development and build infrastructure that turns that source code into something we can develop and deploy efficiently.
Next Lesson
**Vite Project Structure & Configuration**
Next we'll go deeper into:
vite.config.ts│├── Plugins├── Server├── Proxy├── Aliases├── Environment├── Build└── Dependency Optimization
We'll also build a React + Vite + TypeScript + Spring Boot development setup so you understand how the frontend and backend work together in a real enterprise application.