Stop 10 · React BasicsTopics · 3/11

Setting Up React with Vite

Part of the Web Development Roadmap

In short

Five minutes from now you can have a React app running in your browser that reloads instantly every time you save. Vite does the heavy setup work so you can start building.

Vite is a fast build tool that creates a ready-to-run React project with one command and reloads the page instantly as you save changes.

The jaadu opens a cardboard meal kit box on a kitchen table, revealing neatly packed little bowls of vegetables and spices.

Think of it like this

A ready-to-cook meal kit

Instead of shopping for twelve ingredients and measuring spices, you open a meal kit: everything's portioned, labelled and ready. Vite is a meal kit for React projects. One command gives you the folders, config and a dev server already working, so you go straight to the cooking.

The big ideas

What you need to know

Key files

index.html is the single page, src/main.jsx mounts React into it, and src/App.jsx is your first component.

Fast refresh

The dev server updates only what changed, often keeping your component's state, so you see edits almost instantly.

npm scripts

npm run dev for development, npm run build to create the optimised dist folder for hosting, npm run preview to test that build.

node_modules stays local

It's huge and recreated with npm install, so it's already in the .gitignore Vite creates.

How it works

Creating your first app

  1. 1

    Check Node

    Run node -v. You need a recent LTS version of Node.js installed.

  2. 2

    Create

    Run npm create vite@latest, name the project and choose React, then JavaScript.

  3. 3

    Install

    cd into the folder and run npm install to download React and Vite.

  4. 4

    Run

    npm run dev starts the server. Open the localhost link it prints.

  5. 5

    Edit

    Change src/App.jsx, save, and the browser updates instantly.

See it in code

Walk through the code

bash
1node -v                          # check Node.js is installed2npm create vite@latest my-app -- --template react3cd my-app4npm install5npm run dev6#   VITE ready7#   Local: http://localhost:5173/8 9npm run build                     # later: create the production files in dist/

1/4Vite needs Node.js. If this fails, install the LTS version from nodejs.org.

The --template react part skips the questions. Press Ctrl+C in the terminal to stop the dev server.

Save yourself the pain

Common mistakes

Oops

Running npm run dev from the parent folder and getting 'Missing script: dev'.

Do this instead

cd into the project folder first. package.json must be in the folder where you run npm commands.

Oops

Using the old create-react-app tutorials.

Do this instead

create-react-app is deprecated. Use Vite, or a framework like Next.js, as the React docs now suggest.

Your mission

Make it yours

~20 min

Quick check

Which command starts the Vite development server?

Go deeper

  1. 1Create a project with npm create vite@latest and choose React.
  2. 2Explore the generated files and find where the App component is rendered.
  3. 3Run npm run build and look at the optimised files in the dist folder.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge