Skip to content
ClapelloNotes by Barath
ReactCh 02 · 4/6
Beginner4 min readUpdated

React / 07

A real React project with Vite

TL;DR

One command creates a React project with a dev server, a production build and sensible defaults. Here's what each file does, plus the Parcel way.

Create the project

You need Node.js 20.19+ or 22.12+. Then:

  1. Scaffold

    npm create vite@latest tasty-bites -- --template react creates a folder with everything in it. The -- passes --template through npm to the create tool.
  2. Install

    cd tasty-bites then npm install downloads React, Vite and the rest into node_modules.
  3. Run

    npm run dev starts the dev server. Open http://localhost:5173.

Leave out --template and it asks you questions instead. react-ts gives the same thing with TypeScript.

What you get

  • tasty-bites/
  • index.htmlentry point: has #root and loads main.jsx
  • package.jsonscripts + dependencies
  • vite.config.jsturns on the React plugin
  • .gitignorenode_modules, dist…
  • public/copied as-is (favicon)
  • src/
  • main.jsxcreateRoot(...).render(<App />)
  • App.jsxyour first component
  • index.css, App.css
  • assets/images you import

1 · browser asks for /

index.html
<script type="module" src="/src/main.jsx">

2 · the entry script

main.jsx
imports and renders

3 · your UI

<App />
The start-up chain: the browser loads index.html, which loads src/main.jsx, which renders <App /> into #root.

Three files do the real work:

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Tasty Bites</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>
src/main.jsx
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./index.css";
import App from "./App.jsx";
 
createRoot(document.getElementById("root")).render(
  <StrictMode>
    <App />
  </StrictMode>
);
vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
 
export default defineConfig({
  plugins: [react()],
});
  • index.html is the entry point. Vite starts here and follows the <script> to main.jsx.
  • main.jsx is the same createRoot + render from Chapter 1, now rendering a component. StrictMode adds extra development-only checks.
  • vite.config.js turns on the React plugin, which compiles JSX and enables Fast Refresh.

The scripts

ScriptWhat it does
npm run devDev server at localhost:5173 with instant updates
npm run buildProduction build into dist/
npm run previewServes dist/ at localhost:4173 so you can test the real build
npm run lintChecks your code for mistakes (the template ships a linter)

To deploy, you upload dist/. It's just static files, so any static host can serve it.

The same app with Parcel

Parcel needs no config file at all. Setting it up by hand shows every piece:

mkdir tasty-bites && cd tasty-bites
npm init -y
npm install react react-dom
npm install -D parcel
# create src/index.html and src/main.jsx like the Vite ones
npm start   # dev server at http://localhost:1234
package.json
{
  "name": "tasty-bites",
  "source": "src/index.html",
  "scripts": {
    "start": "parcel",
    "build": "parcel build"
  },
  "dependencies": { "react": "^19.3.1", "react-dom": "^19.3.1" },
  "devDependencies": { "parcel": "^2.16.4" }
}
.gitignore
node_modules
dist
.parcel-cache

The source field tells Parcel where to start, so the scripts don't need a file name. Without it you'd write parcel src/index.html. Parcel spots React in your dependencies and compiles JSX automatically.

Gotchas

Recall

Can you answer these?

0/5

Answer out loud (or in your head) before you tap. That's what makes it stick.

Saved on this device only. No login.