Sub topic 11
Tour of the generated files
This chapter assumes you have run npm create vite@latest my-app -- --template react, can read basic JSX, and know what an ES module is. Here you will learn what each generated file does, so you know where to make changes.
The layout
After npm install, the project folder looks like this:
my-app/
├── index.html
├── package.json
├── vite.config.js
├── eslint.config.js
├── public/
├── src/
│ ├── main.jsx
│ ├── App.jsx
│ ├── App.css
│ ├── index.css
│ └── assets/
└── node_modules/The exact files vary a little between template versions. The roles below stay the same.
index.html
Unlike many older tools, Vite treats index.html as the entry point of the app. It sits at the project root, not inside public/. It contains an empty <div id="root"></div> and a script tag with type="module" that loads /src/main.jsx. React fills that div with your UI at runtime.
src/main.jsx
This file connects React to the page. It finds the #root element, creates a React root with createRoot, and renders <App /> inside <StrictMode>. StrictMode adds extra checks in development only. For example, it runs some functions twice to expose side effects that should not be there.
src/App.jsx
App is the top-level component. Everything you build is nested inside it. Treat it as a starting point and replace its contents freely.
package.json
This file describes the project and holds its scripts:
| Script | What it does |
|---|---|
| `npm run dev` | Starts the dev server with hot updates |
| `npm run build` | Writes an optimized bundle to `dist/` |
| `npm run preview` | Serves `dist/` locally for a final check |
| `npm run lint` | Runs ESLint on your code |
The dependencies section lists react and react-dom. The devDependencies section lists Vite, the React plugin, and linting tools. Tools needed only for building belong in devDependencies.
The file also sets "type": "module", so .js files use import and export syntax.
vite.config.js
This file is small. It registers @vitejs/plugin-react, which transforms JSX and enables fast refresh:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
})public/ and src/assets/
Files in public/ are copied to the output as they are, and you refer to them by absolute path, such as /logo.svg. Files in src/assets/ are imported from JavaScript, so Vite can process them and add a content hash to the output filename.
Folders you should not edit
node_modules/holds installed packages. npm recreates it frompackage.json, so you never edit it or commit it.dist/appears after a build. It is generated output.
Exercise
You add a new image and want to import it in a component so Vite can give it a hashed filename in the production build. Should it go in public/ or src/assets/, and why?
Show answer
Put it in src/assets/. Files imported from source code are processed by Vite, which can hash their names for caching. Files in public/ are copied unchanged and are not processed.
Exercise
Which file contains the <div id="root"> element, and which file tells React to render into it?
Show answer
index.html contains the div. src/main.jsx calls createRoot(document.getElementById('root')).render(...) to render the app into it.