TExcelTAD
Home › Vite › Vite Get Started

Vite Get Started

To use Vite you need Node.js and a package manager (npm ships with Node; pnpm, Yarn and Bun work too). Vite 8 requires Node.js 20.19+ or 22.12+.

Check your Node version

bash · try it yourself
node --version
npm --version
v22.14.0
10.9.2

If the version is too old, install a current LTS release from nodejs.org or with a version manager such as nvm or fnm.

Scaffold a project

The official scaffolding tool is create-vite. You run it through npm create, which downloads the latest version on the fly:

bash · try it yourself
npm create vite@latest
> npx
> create-vite

│
◆  Project name:
│  my-vite-app
│
◆  Select a framework:
│  ● Vanilla
│  ○ Vue
│  ○ React
│  ○ Preact
│  ○ Lit
│  ○ Svelte
│  ○ Solid
│  ○ Qwik
│  ○ Angular
│  ○ Others
│
◆  Select a variant:
│  ● TypeScript
│  ○ JavaScript
│
◇  Scaffolding project in /home/me/my-vite-app...
│
└  Done. Now run:

  cd my-vite-app
  npm install
  npm run dev

The prompts ask for a folder name, a framework and a language variant. Use the arrow keys and Enter to choose.

Skip the prompts with a template

For scripts, tutorials and CI you can pass everything on the command line. With npm 7+ the extra -- is required so that --template reaches create-vite instead of npm itself:

bash · try it yourself
npm create vite@latest shop-ui -- --template react-ts
> npx
> create-vite shop-ui --template react-ts

│
◇  Scaffolding project in /home/me/shop-ui...
│
└  Done. Now run:

  cd shop-ui
  npm install
  npm run dev

Common template names:

Template Stack
vanilla / vanilla-ts Plain JavaScript / TypeScript
react / react-ts React (SWC variants: react-swc, react-swc-ts)
vue / vue-ts Vue 3 single-file components
svelte / svelte-ts Svelte 5
preact, lit, solid, qwik + -ts for TypeScript

Tip: Use . as the project name to scaffold into the current (empty) folder: npm create vite@latest . -- --template vanilla.

Install and run

bash · try it yourself
cd my-vite-app
npm install
npm run dev
added 12 packages, and audited 13 packages in 3s

found 0 vulnerabilities

> my-vite-app@0.0.0 dev
> vite


  VITE v8.3.4  ready in 254 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

Open http://localhost:5173/ in your browser. Leave the terminal running — the dev server keeps watching your files. Stop it with Ctrl+C.

The scripts in package.json

The template wires the CLI into npm scripts. A TypeScript template looks like this:

json
{
  "name": "my-vite-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview"
  },
  "devDependencies": {
    "typescript": "~5.9.3",
    "vite": "^8.3.4"
  }
}

Note "type": "module": it tells Node that .js files in the project are ES modules, which is also why vite.config.js can use import/export.

Note: Vite is a dev dependency. Your users never download Vite; they download the files Vite produces in dist/.

Adding Vite to an existing folder

You don't have to use the scaffolder. Any folder with an index.html can become a Vite project:

bash · try it yourself
mkdir plain-site && cd plain-site
npm init -y
npm install -D vite
npx vite
Wrote to /home/me/plain-site/package.json: { ... }

added 12 packages, and audited 13 packages in 2s

found 0 vulnerabilities

  VITE v8.3.4  ready in 198 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help

Keyboard shortcuts

While the dev server runs, type a letter and press Enter:

Key Action
r Restart the server
u Show the server URLs again
o Open the app in the browser
c Clear the console
q Quit
h Show this help

Test yourself

Why is -- needed in npm create vite@latest app -- --template vue?

  1. It enables TypeScript
  2. It forwards the following flags to create-vite instead of npm
  3. It installs dependencies automatically
  4. It is a comment

What is the default dev server URL?

  1. http://localhost:3000/
  2. http://localhost:8080/
  3. http://localhost:5173/
  4. http://localhost:4173/

Which package.json field lets vite.config.js use import syntax?

  1. "main": "index.js"
  2. "type": "module"
  3. "private": true
  4. "esm": true