Deploy Many Vite Demos as One Static Site: A Gallery Page, One Build Command and import.meta.env.BASE_URL
Nine front-end demos, one link: a card per demo from demos.ts, a build:all script that runs vite build --base /<slug>/ for each into dist (about 20 MB in total), image paths from import.meta.env.BASE_URL, a vite preview click-through, any static host, and a recruiter pitch in three sentences.
What you will learn
- Drive a gallery page from one typed list of demos
- Build every Vite demo into its own sub-folder with --base in a single build:all script
- Build public-file addresses from import.meta.env.BASE_URL so images survive deployment under a sub-path
- Check the build with vite preview, deploy dist to any static host, and present it with a 30-second capture and a three-sentence pitch
Before you start
- A React project built with Vite
- npm scripts
Imagine you cooked nine really good dishes, but they're in nine different kitchens and nobody can find them. That's a set of demos sitting in separate folders. In this lesson we put everything from this part in one place: one gallery page, one build, one static host, and one link you can send to a recruiter. Work that nobody can open is work that doesn't exist.
A card for every demo
Each card has a desktop screenshot, with the phone screenshot tucked in the corner. The cards come from a simple list in src/demos.ts:
// One entry per demo. `slug` is the folder name and the sub-path in the deployed site.
export type Demo = { slug: string; title: string; blurb: string; tags: string[]; lecture: string }
export const demos: Demo[] = [
// ...
{ slug: 'product-3d', title: 'Aurel One', lecture: 'S04L01',
blurb: 'A headphone product page: the 3D model turns with scroll, swatches repaint it, the buy box follows.',
tags: ['R3F', 'scroll-linked 3D', 'e-commerce'] },
// ...
]
The page loops over the list and draws one card per entry. Each card links to ./${demo.slug}/, the sub-folder of that demo. To add a demo, you add one entry to the list.
One command builds the whole site
scripts/build-all.mjs, called by npm run build:all:
// Builds the gallery, then every demo into dist/<slug>/ so the whole folder deploys as one static site.
const slugs = ['scroll-story', 'glass-fluid', 'animated-components', 'r3f-basics', 'shader-effects',
'scroll-flythrough', 'product-3d', 'portfolio-room', 'orbit-launch']
const root = resolve(import.meta.dirname, '..')
const run = (cmd, cwd) => execSync(cmd, { cwd, stdio: 'inherit' })
run('npx vite build', root) // gallery first: it empties dist/
for (const slug of slugs) {
const dir = resolve(root, '..', slug)
if (!existsSync(resolve(dir, 'node_modules'))) { console.warn(`skip ${slug}: run npm install there first`); continue }
// --base makes every asset URL start with /<slug>/ ; the demos use import.meta.env.BASE_URL for public files
run(`npx vite build --base /${slug}/ --outDir "${resolve(root, 'dist', slug)}" --emptyOutDir`, dir)
}
The gallery builds first (it empties dist), then each demo builds with its own base path into its own folder. The result is the gallery at the top and one folder per demo. The biggest is the scroll fly-through at nearly 7 MB; the whole site is about 20 MB of plain files.
Each demo lives under its own path
Here's a small detail that breaks many deployments. The gallery sits at the root, the product page under /product-3d/, and Orbit (the sample team project app) under /orbit-launch/. A plain src="/fallback.png" looks in the site root, not inside the demo folder, so the image goes missing after deploy. The product page builds its fallback images from the base instead:
<img key={f.id} src={`${import.meta.env.BASE_URL}fallback-${f.id}.png`} ... />
The base is just / while you develop, and /product-3d/ after the build. One line works in both places. The gallery does the same for its thumbnails:
const thumb = (slug: string, w: 1440 | 390) => `${import.meta.env.BASE_URL}thumbs/${slug}-${w}.webp`
Always build file addresses from the base.
Click through before you ship
npm run build:all
npx vite preview
Open localhost:4173. This serves the built files, exactly what a host will serve. Click every card: does each one open with no missing image? Does the back button return to the gallery? Look at a narrow screen too. One thing to know: the portfolio room's contact form needs its back-end server, so on a static host it shows an error. Preview shows you the truth before anyone else sees it.
It's only files, so any static host works
| Host | How |
|---|---|
| GitHub Pages | Publish from your repository |
| Netlify | Connect the repository or drop the folder |
| Vercel | Import the repository; it builds for you |
| Cloudflare Pages | Connect the repository and pick the folder |
Whichever you choose, it asks the same two things. The build command is npm run build:all, and the output folder is dist. The buttons differ; the two answers don't.
Show it moving
Being online isn't enough; you also need to present it. Make a 30-second capture of each demo:
- Start fresh. Reload, so the first thing a person sees is the opening.
- Do one thing. Scroll the story, spin the product, or click an object.
- Stop at 30 seconds. Short enough that a busy person watches all of it.
A before and after tells the story without a word: Orbit hand-built, then Orbit reimagined.
The recruiter pitch: three sentences, one link
- What it is: nine small front ends, one link, each with a 30-second capture.
- What you did: built with React, three.js and Tailwind, with AI as your assistant and you reviewing every line.
- What it shows: that you can ship. Built, deployed and running, not just a screenshot.
Send the link, and offer to walk them through any one demo.
Common mistakes
- Root-relative paths to public files. They break under a sub-path. Use
import.meta.env.BASE_URL. - Skipping
vite preview. The dev server hides base-path bugs. - Expecting a back end on a static host. Forms that need a server will error.
- Long screen recordings. Thirty seconds, one action.
Try it yourself
Add a tenth card with one entry in demos.ts and a screenshot. Run build:all and preview it. Then deploy dist to a static host and record your 30-second capture.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Backend vs Frontend: What Runs Where, and Why the Server Is the One You Trust
Every web app has two halves. The front end runs on the user's device and is trusted with nothing; the back end holds the data, the secrets and the rules. Checked with real requests to a Django blog.
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
