Vite Project Structure
A freshly scaffolded Vite project is deliberately small. Knowing what each file does makes it much easier to grow the project later.
The vanilla-ts template
npm create vite@latest my-app -- --template vanilla-ts
cd my-app
ls -A> npx
> create-vite my-app --template vanilla-ts
│
◇ Scaffolding project in /home/me/my-app...
│
└ Done.
.gitignore index.html package.json public src tsconfig.json
The full tree:
my-app/
├── .gitignore
├── index.html ← entry point of the app
├── package.json ← scripts + dependencies
├── tsconfig.json ← TypeScript settings (type-checking only)
├── public/
│ └── vite.svg ← copied to dist/ as-is
└── src/
├── main.ts ← first module loaded by index.html
├── counter.ts ← a small example module
├── style.css ← imported from main.ts
└── typescript.svg ← an asset imported from codeWhat each part is for
| Path | Role |
|---|---|
index.html |
The real entry. Vite reads it and follows its <script type="module"> and <link> tags |
src/ |
Your source code. Everything here goes through Vite's transform pipeline |
public/ |
Static files served at the site root and copied unchanged to dist/ |
package.json |
npm scripts (dev, build, preview) and dependencies |
tsconfig.json |
Editor + tsc settings; Vite itself only strips types |
vite.config.ts |
Optional. Not in the vanilla template — add it when you need settings |
node_modules/ |
Installed packages (ignored by git) |
dist/ |
Created by vite build; the folder you deploy (ignored by git) |
Note:
src/is only a convention. Vite does not care where your modules live as long asindex.html(directly or indirectly) imports them.
How the files connect
index.html loads /src/main.ts; main.ts imports CSS, an image and another module. Vite discovers the whole app by following these imports — the module graph.
index.html
└─ /src/main.ts
├─ ./style.css
├─ ./typescript.svg (returns a URL)
├─ /vite.svg (from public/)
└─ ./counter.tsThe two modules look roughly like this:
// src/counter.ts
export function setupCounter(element: HTMLButtonElement) {
let counter = 0;
const setCounter = (count: number) => {
counter = count;
element.innerHTML = `count is ${counter}`;
};
element.addEventListener('click', () => setCounter(counter + 1));
setCounter(0);
}// src/main.ts
import './style.css';
import typescriptLogo from './typescript.svg';
import { setupCounter } from './counter.ts';
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<img src="${typescriptLogo}" alt="TS" width="64">
<button id="counter" type="button"></button>
`;
setupCounter(document.querySelector<HTMLButtonElement>('#counter')!);Walking a module graph
Vite (and its bundler) build a graph of who imports whom. The playground walks a tiny hand-written graph the same way — depth-first, visiting each module once:
const graph = {
'index.html': ['/src/main.ts'],
'/src/main.ts': ['./style.css', './typescript.svg', './counter.ts'],
'./counter.ts': [],
'./style.css': [],
'./typescript.svg': [],
};
const seen = new Set();
function visit(id, depth) {
if (seen.has(id)) return;
seen.add(id);
console.log(' '.repeat(depth) + id);
for (const dep of graph[id]) visit(dep, depth + 1);
}
visit('index.html', 0);
console.log('modules:', seen.size);index.html
/src/main.ts
./style.css
./typescript.svg
./counter.ts
modules: 5
That count is exactly what vite build reports as "modules transformed".
After a build
npm run build
ls dist dist/assets> my-app@0.0.0 build
> tsc && vite build
vite v8.3.4 building client environment for production...
✓ 7 modules transformed.
dist/index.html 0.46 kB │ gzip: 0.30 kB
dist/assets/typescript-BnLe9Rqz.svg 1.41 kB │ gzip: 0.70 kB
dist/assets/index-DiwrgTda.css 1.20 kB │ gzip: 0.62 kB
dist/assets/index-C3k9pQ2x.js 3.03 kB │ gzip: 1.59 kB
✓ built in 112ms
dist:
assets index.html vite.svg
dist/assets:
index-C3k9pQ2x.js index-DiwrgTda.css typescript-BnLe9Rqz.svg
Notice that vite.svg from public/ lands at the root of dist/ with its original name, while src/ files are bundled into assets/ with content hashes in their names.
Tip: Add a
vite.config.tsonly when you need it. A project with no config file uses sensible defaults: root = current folder,outDir=dist, port 5173.
Test yourself
Which file does Vite treat as the entry point of a normal app?
- src/main.ts
- package.json
- index.html
- vite.config.ts
What happens to files in public/ during a build?
- They are bundled and hashed
- They are copied to dist/ unchanged
- They are deleted
- They are converted to modules
Is a vite.config file required?
- Yes, Vite fails without it
- Only for TypeScript projects
- No, Vite has sensible defaults
- Only in production