A React, Vue or Svelte application built with Vite produces HTML, CSS and JavaScript files. There is no application server to run: you just serve the dist folder. Webgune offers two ways to do it, depending on the nature chosen for the service.
Choosing the service nature
| Static site (recommended) | Application | |
|---|---|---|
| Server | Nginx 1.28 | serve package on Node.js |
Unknown address (/account/profile) | Returns index.html | 404 error |
/about serves about.html | Yes | No |
Hidden files (.env, .git) | Never served | Depends on serve behavior |
| Node.js in the image | No | Yes |
A single-page application that handles its routes in the browser (React Router, Vue Router, TanStack Router) must use the Static site nature. Otherwise, reloading the page on any address other than / returns a 404 error.
The nature is chosen at creation, in Configure service, or later in the service settings. The change takes effect at the next build.
What the build runs
Static site nature
- Frozen installation of dependencies, from the committed lock file.
npm run build(your script, usuallyvite build).- Copy of the first folder that contains an
index.htmlamongdist,build,out,_site,.output/public,public,www. - Nginx image that serves this folder on the service's port.
Dependencies, sources and Node.js are not in the final image.
Application nature
Auto build recognizes Vite through vite.config.js, vite.config.ts or vite.config.mjs. It runs npm run build, then starts serve dist -p $PORT. The serve package is installed in the image at build time.
Create React App (react-scripts), Vue CLI and Preact CLI are served with a fallback to index.html, even in the Application nature. Angular too. The full list is on Supported frameworks.
The lock file
The build installs exactly what package-lock.json, bun.lock, pnpm-lock.yaml or yarn.lock describes. Without this file, or if it no longer matches package.json, the build fails. After any dependency change, run the install locally and commit the file (How builds work).
Environment variables
Vite only sends the browser the variables prefixed with VITE_:
VITE_API_URL=https://api.example.com
VITE_APP_NAME=MyApp
const apiUrl = import.meta.env.VITE_API_URL;
- These values are written into the JavaScript at build time. Changing one requires a new build, not a simple restart.
- Anything prefixed with
VITE_is readable by any visitor in the site's code. Never put a secret key there. - If the Build scope in the Variables panel is filled in, the build receives only that: your
VITE_*variables must be in it (Environment variables).
A Create React App application uses the REACT_APP_ prefix, with the same rules.
Calling your API
The site runs in the visitor's browser, not on Webgune's servers. It must therefore call your API at its public address (https://api.example.com), never at an address internal to the project.
If the site and the API have different domains, the API must allow the site's origin (CORS headers). With Express and the cors package:
import cors from "cors";
app.use(cors({ origin: "https://www.example.com" }));
Monorepo subfolder
The build analyzes the repository root. If the Vite application is in apps/web, add a build script at the root that builds it, for example npm run build --workspace apps/web, and have the output produced in a folder from the list above. Otherwise, use a Dockerfile.
Common errors
| Symptom | Cause | What to do |
|---|---|---|
| 404 error when reloading a page | Application nature with a browser-side router | Switch to the Static site nature |
| "No index.html found" | The build does not produce a known folder | Check build.outDir in vite.config |
A variable is undefined | Missing VITE_ prefix, or variable absent from the Build scope | Add the prefix, then redeploy |
| Blank page, JS files returning 404 | base in vite.config does not match the site's address | Leave base: "/" for a site served at the root |
| The install rejects the lock file | File out of date with package.json | Regenerate it locally and commit it |
Updated on