DEPLOYMENT

Vite Deployment: Build, Preview, and Publish the Right Folder

Use Vite’s production output, choose the right base path, and diagnose modules or assets that load locally but fail online.

TL;DR: Use npm run build, preview the result over HTTP, and publish the output directory—usually dist. Keep Vite's base at / when serving from a hostname root unless you intentionally host under a subdirectory.

Introduction

The easiest Vite deployment mistake is to upload what you edit instead of what Vite generates. A browser cannot load your development import graph as though the Vite dev server were still present. It needs the compiled HTML, bundles, stylesheets and assets generated by a production build.

The practical difference shows up when you open the output HTML. Instead of referring to /src/main.tsx, it usually refers to a fingerprinted script under /assets/. Slow down long enough to check that the exact paths in that HTML are the ones your host can serve.

What is Vite deployment?

Vite deployment publishes the prepared bundle emitted by Vite's production build command to a compatible host. For a regular static app the default target is dist. Set the output path in your build configuration and your host if you choose a different one; the two settings must agree.

KairoBase can serve a prepared Vite bundle without npm. When isolated builds are enabled, it can also install public locked dependencies and run a named npm script for a supported single-package project. Review the build guide if your project relies on an install lifecycle hook, a private registry or outbound network requests during build.

Why previewing the output matters

  • Vite starts a development server with hot reloading. That server serves source and can have request behavior missing from your public host.
  • Previewing production output finds mistakes that a workbench full of development conveniences can hide.
  • A path issue can look like a framework failure. Read requested URLs and response types before rewriting routes or components.

How Vite chooses asset URLs

The default root address

If your site is https://example.kairoweb.bond/, the usual Vite base is /. An HTML reference such as /assets/app-AbCd.js must map to assets/app-AbCd.js in the dist directory. Open the built page source and compare with the directory rather than assuming what the bundler wrote.

Hosting under a directory

If a separate service publishes at https://example.com/docs/, a configured base of /docs/ can be appropriate. Publishing that output at a root hostname without rebuilding can produce 404s on every asset request. Browser routing must also be aware of any deliberate base path. Use one URL scheme for each environment and generate configuration from it consistently.

Values defined at build time

Vite exposes client values with the VITE_ prefix by default. That is useful for public endpoints and interface switches. It is not a way to hide provider secrets. Reduce surprises by recording environment-specific public values with each release, and ensure a preview cannot accidentally call production if the API makes writes.

SymptomLikely place to lookWhat to compare
Blank pageEntry module or browser exceptionScript URL and status against built output
Home works, refresh failsClient routingEdge fallback and actual route pathname
Styles or fonts are absentAsset URLBase path, file name and content type

Practical steps

  1. Use a current supported Node version and update the lockfile alongside intentional dependency edits.
  2. Run the project's build script and use npm run preview when your package defines it. Verify a route and inspect network requests.
  3. ZIP the generated files for static upload, or set your build and output fields in the website's deployment form.
  4. After publishing, test the site over HTTPS without your development server running. If there is a problem, keep a copy of the exact public response and release ID.

Common mistakes

  • Uploading node_modules or the original source directory as public output.
  • Choosing a base path pasted from another host's deployment tutorial.
  • Using an asset import that resolves on a case-insensitive filesystem but points to a different filename on the host.

Frequently asked questions

Do I upload the dist folder or its contents? Upload the contents or a ZIP with a single enclosing output folder. The published root needs to contain index.html.

Is a local Vite preview a public production server? No. It is a convenient way to inspect generated files before you host them elsewhere.

Can I override the output directory? Yes. Set the repository's Vite output and tell the build runner the same relative directory.

Why does a public image show a broken icon? Verify the final image URL and whether the image was copied into the output. A source-relative path may not survive bundling.

Can a Vite app call APIs? Yes, over normal browser requests. The backend still needs authentication and appropriate CORS settings.

Conclusion

Match the output folder, URL base and routing model before turning a build into a release. Use the KairoBase deployment workflow and the Vite static deployment documentation to confirm the configuration.

Related reading