TExcelTAD
Home › Vite › Vite Intro

Vite Introduction

Vite (French for "quick", pronounced veet) is a build tool for modern web projects. It gives you two things in one package:

  1. A development server that starts almost instantly and updates the page the moment you save a file.
  2. A production build command that bundles, minifies and fingerprints your code so it loads fast for real users.

Vite works with plain HTML/CSS/JavaScript, with TypeScript, and with every major framework — React, Vue, Svelte, Solid, Preact, Lit and more. Many frameworks (Nuxt, SvelteKit, Astro, Remix/React Router, Analog) are built on top of it.

What is a build tool?

Browsers understand HTML, CSS and JavaScript. Real projects, however, are written in a richer form:

  • hundreds of small modules instead of one big script,
  • TypeScript, JSX or .vue/.svelte single-file components,
  • npm packages imported by name (import { format } from 'date-fns'),
  • Sass, CSS Modules, images and fonts imported from JavaScript.

A build tool turns that source into something a browser can load efficiently. During development it should be fast and give quick feedback; for production it should produce the smallest, best-cached output possible.

Why Vite is fast

Older bundler-based dev servers (for example classic webpack setups) bundled your entire application before the first page could be shown. On a large app that meant waiting tens of seconds on every start.

Vite takes a different approach in development:

Problem Vite's answer
Your own source code changes often Served as native ES modules: the browser requests each file, Vite transforms only that file on demand
npm dependencies are big and rarely change Pre-bundled once and cached, so a library with 600 internal files becomes one request
Rebuilding after an edit is slow Hot Module Replacement (HMR) swaps only the changed module, keeping app state
TypeScript/JSX compile time Transpiled with a very fast native compiler (Oxc in Vite 8, esbuild in older versions)

For production, Vite bundles everything with Rolldown, a Rust-based bundler with a Rollup-compatible API (Vite 5–7 used Rollup). Bundling is still the right choice for production because it avoids hundreds of network round-trips and enables tree-shaking and minification.

Native ES modules in one example

The key idea behind the Vite dev server is that modern browsers can load modules themselves. The playground below simulates two "files" with data: URLs and lets the browser link them — no bundler involved.

js · try it yourself
const mathFile = 'export const double = (n) => n * 2;';
const url = 'data:text/javascript,' + encodeURIComponent(mathFile);

(async () => {
  const math = await import(url);
  console.log('double(21) =', math.double(21));
})();
double(21) = 42

In a Vite project the same thing happens with real files: main.js imports ./math.js, the browser requests /math.js, and Vite answers with the (transformed) file.

Your first taste of the CLI

Every Vite project has three main commands. You will learn each one in detail later; for now just notice how little output there is.

bash · try it yourself
npm create vite@latest hello-vite -- --template vanilla
cd hello-vite
npm install
npm run dev
> npx
> create-vite hello-vite --template vanilla

│
◇  Scaffolding project in /home/me/hello-vite...
│
└  Done.

added 12 packages, and audited 13 packages in 4s

found 0 vulnerabilities

> hello-vite@0.0.0 dev
> vite


  VITE v8.3.4  ready in 287 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
Command Script What it does
vite npm run dev Starts the dev server with HMR
vite build npm run build Creates an optimized dist/ folder
vite preview npm run preview Serves dist/ locally to check the build

What the page looks like

A Vite starter is just an HTML page that loads a module script. This live example is the same idea, without any tooling:

html · try it yourself
<!doctype html>
<html>
  <body style="font-family: system-ui; text-align: center; padding: 2rem">
    <h1>Hello Vite ⚡</h1>
    <button id="counter">count is 0</button>
    <script type="module">
      let count = 0;
      const btn = document.querySelector('#counter');
      btn.addEventListener('click', () => {
        count++;
        btn.textContent = `count is ${count}`;
      });
    </script>
  </body>
</html>

Note: Vite is not a framework. It does not decide how you write components or manage state — it only serves and builds your files. That is why the same tool fits React, Vue, Svelte or no framework at all.

What you will learn

This course walks through the dev server, assets, CSS, TypeScript, environment variables, configuration, plugins, framework templates, production builds, deployment (including Docker + nginx), testing with Vitest, and finishes with exercises and a small multi-page project.

Test yourself

How does the Vite dev server deliver your own source files to the browser?

  1. As one big pre-built bundle
  2. As native ES modules transformed on demand
  3. As CommonJS modules
  4. As a single inline script in index.html

Which tool bundles a Vite 8 project for production?

  1. webpack
  2. Parcel
  3. Rolldown
  4. Babel

Why does Vite pre-bundle npm dependencies?

  1. To type-check them
  2. To turn many internal module files into a few cached requests
  3. To upload them to a CDN
  4. Because browsers cannot run npm packages at all