Skip to the workspace
Pebellslearn by building
Components and JSX  ›  Lesson

Starting a Project with Vite

Vite 12 minVite creates a ready-to-run React project and serves it with instant reloads while you work, then bundles it into plain static files for release.

react / Starting a Project with Vite

Explore each scene at your own pace.

01 · The rule

The rule

Starting a Project with Vite

A browser cannot read JSX, and a real app is made of dozens of files that need to be stitched together. Before you write a single component you need a tool that does that stitching for you, instantly, every time you save. Vite is the tool most new React projects start with.

The rule

Create, install, dev: three commands, then React is live.

Create generates a small, working project from a template:

npm create vite@latest reading-list -- --template react
cd reading-list
npm install
npm run dev

Install (npm install) downloads everything listed in package.json, such as react and react-dom, into a node_modules folder.

Dev (npm run dev) starts a local development server, usually at http://localhost:5173. When you save a file, the change appears in the browser almost immediately, often without losing what was on screen.

The generated project is small enough to learn by heart:

reading-list/
  index.html        the one real HTML page, with <div id="root">
  package.json      dependencies and scripts
  vite.config.js    Vite settings (the React plugin lives here)
  src/
    main.jsx        entry point: puts <App /> into #root
    App.jsx         your first component

The entry point is short:

import { createRoot } from 'react-dom/client';
import App from './App.jsx';

createRoot(document.getElementById('root')).render(<App />);

Files that contain JSX use the .jsx extension (or .tsx with TypeScript), which tells Vite to transform them into plain JavaScript the browser can run. Vite itself needs a recent version of Node.js installed; check with node --version if the create command complains.

When you are ready to publish, npm run build writes optimised, plain HTML, CSS and JavaScript into a dist folder that any static host can serve.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.